ZQuest Classic Coverage Report


Directory: src/
File: src/zc/ffscript.cpp
Date: 2025-05-30 08:30:52
Exec Total Coverage
Lines: 7002 23519 29.8%
Functions: 420 951 44.2%
Branches: 3973 18412 21.6%

Line Branch Exec Source
1 #include <cstdint>
2 #include <deque>
3 #include <string>
4 #include <sstream>
5 #include <math.h>
6 #include <cstdio>
7 #include <algorithm>
8 #include <ranges>
9 //
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <fstream>
15 #include <filesystem>
16 #include <fmt/format.h>
17 #include <fmt/ranges.h>
18 //
19
20 #include "base/expected.h"
21 #include "base/handles.h"
22 #include "base/general.h"
23 #include "base/mapscr.h"
24 #include "base/qrs.h"
25 #include "base/dmap.h"
26 #include "base/msgstr.h"
27 #include "base/packfile.h"
28 #include "base/misctypes.h"
29 #include "base/initdata.h"
30 #include "base/version.h"
31 #include "zc/maps.h"
32 #include "zasm/serialize.h"
33 #include "zasm/table.h"
34 #include "zc/replay.h"
35 #include "zc/scripting/script_object.h"
36 #include "zc/scripting/types.h"
37 #include "zc/scripting/types/websocket.h"
38 #include "zc/zasm_optimize.h"
39 #include "zc/zasm_utils.h"
40 #include "zc/zc_ffc.h"
41 #include "zc/zc_sys.h"
42 #include "zc/jit.h"
43 #include "zc/script_debug.h"
44 #include "base/zc_alleg.h"
45 #include "base/zc_math.h"
46 #include "base/zc_array.h"
47 #include "zc/ffscript.h"
48 #include "zc/render.h"
49 #include "zc/zc_subscr.h"
50 #include <time.h>
51 #include "zc/script_drawing.h"
52 #include "base/util.h"
53 #include "zc/ending.h"
54 #include "zc/combos.h"
55 #include "drawing.h"
56 #include "base/colors.h"
57 #include "pal.h"
58 #include "zinfo.h"
59 #include "subscr.h"
60 #include "zc_list_data.h"
61 #include "music_playback.h"
62 #include "iter.h"
63 #include <sstream>
64
65 #include "zc/zelda.h"
66 #include "particles.h"
67 #include "zc/hero.h"
68 #include "zc/guys.h"
69 #include "gamedata.h"
70 #include "zc/zc_init.h"
71 #include "base/zsys.h"
72 #include "base/misctypes.h"
73 #include "zc/title.h"
74 #include "zscriptversion.h"
75
76 #include "pal.h"
77 #include "base/zdefs.h"
78 #include "zc/rendertarget.h"
79
80 #include "hero_tiles.h"
81 #include "base/qst.h"
82
83 using namespace util;
84
85 #ifdef _WIN32
86 #define SCRIPT_FILE_MODE (_S_IREAD | _S_IWRITE)
87 #else
88 #include <fcntl.h>
89 #include <unistd.h>
90 #include <iostream>
91 #define SCRIPT_FILE_MODE (S_ISVTX | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
92 #endif
93
94 //Define this register, so it can be treated specially
95 #define NUL 5
96 #define MAX_ZC_ARRAY_SIZE 214748
97
98 using namespace util;
99 using std::ostringstream;
100
101 static ASM_DEFINE current_zasm_command;
102 static uint32_t current_zasm_register;
103 // If set, the next call to scripting_log_error_with_context will use this string in addition to whatever
104 // current_zasm_command and current_zasm_register refer to. Must unset after manually.
105 std::string current_zasm_extra_context;
106 // If set, the next call to scripting_log_error_with_context will use this string instead of whatever
107 // current_zasm_command and current_zasm_register refer to. Must unset after manually.
108 std::string current_zasm_context;
109
110 1243089 void scripting_log_error_with_context(std::string text)
111 {
112
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1243089 times.
1243089 if (current_zasm_context.empty())
113 {
114 1243089 std::vector<const char*> context;
115
116
1/2
✓ Branch 0 taken 1243089 times.
✗ Branch 1 not taken.
1243089 const char* register_string = scripting_get_zasm_register_context_string(current_zasm_register);
117
2/2
✓ Branch 0 taken 217649 times.
✓ Branch 1 taken 1025440 times.
1243089 if (register_string)
118
1/2
✓ Branch 0 taken 217649 times.
✗ Branch 1 not taken.
217649 context.push_back(register_string);
119
120
1/2
✓ Branch 0 taken 1243089 times.
✗ Branch 1 not taken.
1243089 const char* command_string = scripting_get_zasm_command_context_string(current_zasm_command);
121
2/2
✓ Branch 0 taken 1234729 times.
✓ Branch 1 taken 8360 times.
1243089 if (command_string)
122
1/2
✓ Branch 0 taken 1234729 times.
✗ Branch 1 not taken.
1234729 context.push_back(command_string);
123
124
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1243089 times.
1243089 if (!current_zasm_extra_context.empty())
125 context.push_back(current_zasm_extra_context.c_str());
126
127
2/2
✓ Branch 0 taken 1237441 times.
✓ Branch 1 taken 5648 times.
1243089 if (context.size())
128
3/6
✓ Branch 0 taken 1237441 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1237441 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1237441 times.
✗ Branch 5 not taken.
1237441 current_zasm_context = fmt::format("{}", fmt::join(context, ", "));
129 else
130 {
131
1/2
✓ Branch 0 taken 5648 times.
✗ Branch 1 not taken.
5648 Z_scripterrlog("%s\n", text.c_str());
132 5648 return;
133 }
134
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 5648 times.
✓ Branch 2 taken 1237441 times.
1243089 }
135
136 1237441 Z_scripterrlog("%s | %s\n", current_zasm_context.c_str(), text.c_str());
137 1237441 current_zasm_context = "";
138 1237441 current_zasm_extra_context = "";
139 1243089 }
140
141 // (type, index) => ScriptEngineData
142 403 std::map<std::pair<ScriptType, int>, ScriptEngineData> scriptEngineDatas;
143
144 extern byte use_dwm_flush;
145 uint8_t using_SRAM = 0;
146
147 int32_t hangcount = 0;
148 bool can_neg_array = true;
149
150 extern byte monochrome_console;
151
152 403 static std::map<script_id, ScriptDebugHandle> script_debug_handles;
153 ScriptDebugHandle* runtime_script_debug_handle;
154 // Values may be null.
155 403 static std::map<std::pair<script_data*, refInfo*>, JittedScriptHandle*> jitted_scripts;
156 int32_t jitted_uncompiled_command_count;
157
158 403 CScriptDrawingCommands scriptdraws;
159 403 FFScript FFCore;
160
161 static expected<std::string, std::string> parse_user_path(const std::string& user_path, bool is_file);
162
163 static UserDataContainer<user_dir, MAX_USER_DIRS> user_dirs = {script_object_type::dir, "directory"};
164 static UserDataContainer<user_file, MAX_USER_FILES> user_files = {script_object_type::file, "file"};
165 static UserDataContainer<user_paldata, MAX_USER_PALDATAS> user_paldatas = {script_object_type::paldata, "paldata"};
166 static UserDataContainer<user_rng, MAX_USER_RNGS> user_rngs = {script_object_type::rng, "rng"};
167 static UserDataContainer<user_stack, MAX_USER_STACKS> user_stacks = {script_object_type::stack, "stack"};
168 static UserDataContainer<user_bitmap, MAX_USER_BITMAPS> user_bitmaps = {script_object_type::bitmap, "bitmap"};
169
170 16084665 void script_bitmaps::update()
171 {
172 16084665 auto ids = script_object_ids_by_type[user_bitmaps.type];
173
2/2
✓ Branch 0 taken 35975860 times.
✓ Branch 1 taken 16084665 times.
52060525 for (auto id : ids)
174 {
175
1/2
✓ Branch 0 taken 35975860 times.
✗ Branch 1 not taken.
35975860 auto& bitmap = user_bitmaps[id];
176
3/4
✓ Branch 0 taken 35975860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3655 times.
✓ Branch 3 taken 35972205 times.
35975860 if (bitmap.is_freeing())
177 {
178
1/2
✓ Branch 0 taken 3655 times.
✗ Branch 1 not taken.
3655 bitmap.mark_can_del();
179
1/2
✓ Branch 0 taken 3655 times.
✗ Branch 1 not taken.
3655 delete_script_object(id);
180 3655 }
181 }
182 16084665 }
183
184 648117 user_bitmap& script_bitmaps::get(int32_t id)
185 {
186
3/4
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 648108 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
648117 static user_bitmap fake;
187
188 648117 current_zasm_context = "script drawing";
189
1/2
✓ Branch 0 taken 648117 times.
✗ Branch 1 not taken.
648117 if (auto bitmap = user_bitmaps.check(id))
190 {
191 648117 current_zasm_context = "";
192 648117 return *bitmap;
193 }
194
195 return fake;
196 648117 }
197
198 script_bitmaps scb;
199 403 user_rng nulrng;
200 403 zc_randgen script_rnggens[MAX_USER_RNGS];
201
202 FONT *get_zc_font(int index);
203
204 int32_t combopos_modified = -1;
205 static std::vector<word> combo_id_cache;
206
207 void user_dir::setPath(const char* buf)
208 {
209 if(!list)
210 {
211 list = (FLIST *) calloc(1, sizeof(FLIST));
212 }
213 filepath = std::string(buf) + "/";
214 regulate_path(filepath);
215 list->load(filepath.c_str());
216 }
217
218 int32_t CScriptDrawingCommands::GetCount()
219 {
220 al_trace("current number of draws is: %d\n", count);
221 return count;
222 }
223
224 enum class mapdata_type
225 {
226 None,
227 CanonicalScreen,
228 TemporaryCurrentScreen,
229 TemporaryCurrentRegion,
230 TemporaryScrollingScreen,
231 TemporaryScrollingRegion,
232 };
233
234 // Decodes a `mapref` (reference number) for a temporary screen.
235 //
236 // A mapref can refer to:
237 //
238 // - the canonical mapscr data, loaded via `Game->LoadMapData(int map, int screen)`
239 // - a temporary mapscr, loaded via `Game->LoadTempScreen(int layer, int? screen)`
240 // - a temporary mapscr, loaded via `Game->LoadScrollingScreen(int layer, int? screen)`
241 //
242 // The canonical maprefs are >=0, and temporary ones are all negative.
243 //
244 // If temporary, and loaded without specifiying a screen index, we allow combo array variables (like
245 // `ComboX[pos]`) to address any rpos in the region. Otherwise, only positions in the exact screen
246 // referenced by `mapref` can be used (0-175). See ResolveMapdataPos.
247 88751806 static auto decode_mapdata_ref(int ref)
248 {
249 struct decode_result {
250 mapdata_type type;
251 mapscr* scr;
252 int screen;
253 int layer;
254
255 bool temporary() const
256 {
257 return type != mapdata_type::None && type != mapdata_type::CanonicalScreen;
258 }
259
260 45056 bool canonical() const
261 {
262 45056 return type == mapdata_type::CanonicalScreen;
263 }
264
265 2359248 bool current() const
266 {
267
2/2
✓ Branch 0 taken 673570 times.
✓ Branch 1 taken 1685678 times.
2359248 return type == mapdata_type::TemporaryCurrentRegion || type == mapdata_type::TemporaryCurrentScreen;
268 }
269
270 86700881 bool scrolling() const
271 {
272
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 86700881 times.
86700881 return type == mapdata_type::TemporaryScrollingRegion || type == mapdata_type::TemporaryScrollingScreen;
273 }
274 };
275
276
2/2
✓ Branch 0 taken 19066142 times.
✓ Branch 1 taken 69685664 times.
88751806 if (ref >= 0)
277 {
278
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19066142 times.
19066142 if (ref >= TheMaps.size())
279 return decode_result{};
280
281 19066142 int screen = ref % MAPSCRS;
282 19066142 return decode_result{mapdata_type::CanonicalScreen, &TheMaps[ref], screen, 0};
283 }
284
285 // Negative values are for temporary screens.
286
287 69685664 ref = -(ref + 1);
288 69685664 bool is_scrolling = ref & 1;
289 69685664 bool is_region = ref & 2;
290 69685664 int screen = (ref & 0x0000FF00) >> 8;
291 69685664 int layer = (ref & 0x00FF0000) >> 16;
292
293
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69685664 times.
69685664 if (is_region)
294 {
295
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69685664 times.
69685664 if (is_scrolling)
296 screen = scrolling_region.origin_screen;
297 else
298 69685664 screen = cur_screen;
299 69685664 }
300
301 69685664 mapscr* scr = nullptr;
302
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69685664 times.
69685664 if (is_scrolling)
303 {
304 int index = screen * 7 + layer;
305 if (index >= 0 && index < FFCore.ScrollingScreensAll.size())
306 scr = FFCore.ScrollingScreensAll[index];
307 }
308 else
309 {
310
3/6
✓ Branch 0 taken 69685664 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69685664 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 69685664 times.
69685664 if (layer >= 0 && layer <= 6 && is_in_current_region(screen))
311 69685664 scr = get_scr_layer(screen, layer);
312 }
313
314
1/2
✓ Branch 0 taken 69685664 times.
✗ Branch 1 not taken.
69685664 if (!scr)
315 return decode_result{};
316
317 69685664 auto type = mapdata_type::None;
318
2/4
✓ Branch 0 taken 69685664 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69685664 times.
✗ Branch 3 not taken.
69685664 if (is_region && is_scrolling)
319 type = mapdata_type::TemporaryScrollingRegion;
320
2/4
✓ Branch 0 taken 69685664 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 69685664 times.
69685664 else if (is_region && !is_scrolling)
321 69685664 type = mapdata_type::TemporaryCurrentRegion;
322 else if (!is_region && is_scrolling)
323 type = mapdata_type::TemporaryScrollingScreen;
324 else if (!is_region && !is_scrolling)
325 type = mapdata_type::TemporaryCurrentScreen;
326
327 69685664 return decode_result{type, scr, screen, layer};
328 88751806 }
329
330 3387229 static int create_mapdata_temp_ref(mapdata_type type, int screen, int layer)
331 {
332
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3387229 times.
3387229 bool is_scrolling = type == mapdata_type::TemporaryScrollingScreen || type == mapdata_type::TemporaryScrollingRegion;
333
2/2
✓ Branch 0 taken 177544 times.
✓ Branch 1 taken 3209685 times.
3387229 bool is_region = type == mapdata_type::TemporaryScrollingRegion || type == mapdata_type::TemporaryCurrentRegion;
334
335 3387229 int ref = 0;
336 3387229 ref |= is_scrolling ? 1 : 0;
337 3387229 ref |= is_region ? 2 : 0;
338
1/2
✓ Branch 0 taken 3387229 times.
✗ Branch 1 not taken.
3387229 if (!is_region)
339 ref |= ((screen & 0xFF) << 8);
340 3387229 ref |= ((layer & 0xFF) << 16);
341 3387229 return -ref-1;
342 }
343
344 mapscr* GetScrollingMapscr(int layer, int x, int y)
345 {
346 if (!screenscrolling)
347 return nullptr;
348
349 int screen = scrolling_region.origin_screen + map_scr_xy_to_index(x / 256, y / 176);
350 mapscr* m = FFCore.ScrollingScreensAll[screen * 7 + layer];
351 if (!m || !m->is_valid())
352 return nullptr;
353
354 return m;
355 }
356
357 18 int32_t getMap(int32_t ref)
358 {
359
1/15
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
18 switch(ref)
360 {
361 case MAPSCR_TEMP0:
362 return cur_map+1;
363 case MAPSCR_TEMP1:
364 return origin_scr->layermap[0];
365 case MAPSCR_TEMP2:
366 return origin_scr->layermap[1];
367 case MAPSCR_TEMP3:
368 return origin_scr->layermap[2];
369 case MAPSCR_TEMP4:
370 return origin_scr->layermap[3];
371 case MAPSCR_TEMP5:
372 return origin_scr->layermap[4];
373 case MAPSCR_TEMP6:
374 return origin_scr->layermap[5];
375 case MAPSCR_SCROLL0:
376 return scrolling_map+1;
377 case MAPSCR_SCROLL1:
378 return special_warp_return_scr->layermap[0];
379 case MAPSCR_SCROLL2:
380 return special_warp_return_scr->layermap[1];
381 case MAPSCR_SCROLL3:
382 return special_warp_return_scr->layermap[2];
383 case MAPSCR_SCROLL4:
384 return special_warp_return_scr->layermap[3];
385 case MAPSCR_SCROLL5:
386 return special_warp_return_scr->layermap[4];
387 case MAPSCR_SCROLL6:
388 return special_warp_return_scr->layermap[5];
389 default:
390 18 return (ref / MAPSCRS + 1);
391 }
392 18 }
393 42 int32_t getScreen(int32_t ref)
394 {
395
1/15
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
42 switch(ref)
396 {
397 case MAPSCR_TEMP0:
398 return cur_screen;
399 case MAPSCR_TEMP1:
400 return origin_scr->layerscreen[0];
401 case MAPSCR_TEMP2:
402 return origin_scr->layerscreen[1];
403 case MAPSCR_TEMP3:
404 return origin_scr->layerscreen[2];
405 case MAPSCR_TEMP4:
406 return origin_scr->layerscreen[3];
407 case MAPSCR_TEMP5:
408 return origin_scr->layerscreen[4];
409 case MAPSCR_TEMP6:
410 return origin_scr->layerscreen[5];
411 case MAPSCR_SCROLL0:
412 return scrolling_hero_screen;
413 case MAPSCR_SCROLL1:
414 return special_warp_return_scr->layerscreen[0];
415 case MAPSCR_SCROLL2:
416 return special_warp_return_scr->layerscreen[1];
417 case MAPSCR_SCROLL3:
418 return special_warp_return_scr->layerscreen[2];
419 case MAPSCR_SCROLL4:
420 return special_warp_return_scr->layerscreen[3];
421 case MAPSCR_SCROLL5:
422 return special_warp_return_scr->layerscreen[4];
423 case MAPSCR_SCROLL6:
424 return special_warp_return_scr->layerscreen[5];
425 default:
426 42 return (ref % MAPSCRS);
427 }
428 42 }
429
430 654489967 static ffcdata* get_ffc(ffc_id_t ffc_id)
431 {
432 654489967 return &get_scr_for_region_index_offset(ffc_id / MAXFFCS)->getFFC(ffc_id % MAXFFCS);
433 }
434
435 94642 dword get_subref(int sub, byte ty, byte pg = 0, word ind = 0)
436 {
437 byte s;
438
2/2
✓ Branch 0 taken 79480 times.
✓ Branch 1 taken 15162 times.
94642 if(sub == -1) //special; load current
439 {
440
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15162 times.
15162 if (new_sub_indexes[ty] < 0) return 0;
441 15162 s = new_sub_indexes[ty];
442 15162 }
443
1/2
✓ Branch 0 taken 79480 times.
✗ Branch 1 not taken.
79480 else if(unsigned(sub) < 256)
444 79480 s = sub;
445 else return 0;
446 94642 ++ty; //type is offset by 1
447 94642 return (s<<24)|(pg<<16)|((ty&0x7)<<13)|(ind&0x1FFF);
448 94642 }
449 361677 std::tuple<byte,int8_t,byte,word> from_subref(dword ref)
450 {
451 361677 byte type = (ref>>13)&0x07;
452
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 361677 times.
361677 if(!type)
453 return { 0, -1, 0, 0 };
454
455 361677 byte sub = (ref>>24)&0xFF;
456 361677 byte pg = (ref>>16)&0xFF;
457 361677 word ind = (ref)&0x1FFF;
458 361677 return { sub, type-1, pg, ind };
459 361677 }
460
461 282200 std::tuple<ZCSubscreen*,SubscrPage*,SubscrWidget*,byte> load_subscreen_ref(dword ref)
462 {
463 1411000 auto [sub,ty,pg,ind] = from_subref(ref);
464 282200 ZCSubscreen* sbscr = nullptr;
465 282200 SubscrPage* sbpg = nullptr;
466 282200 SubscrWidget* sbwidg = nullptr;
467
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 282200 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
282200 switch(ty)
468 {
469 case sstACTIVE:
470
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 282200 times.
282200 if(sub < subscreens_active.size())
471 282200 sbscr = &subscreens_active[sub];
472 282200 break;
473 case sstPASSIVE:
474 if(sub < subscreens_passive.size())
475 sbscr = &subscreens_passive[sub];
476 break;
477 case sstOVERLAY:
478 if(sub < subscreens_overlay.size())
479 sbscr = &subscreens_overlay[sub];
480 break;
481 }
482
1/2
✓ Branch 0 taken 282200 times.
✗ Branch 1 not taken.
282200 if(sbscr)
483 {
484
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 282200 times.
282200 if(pg < sbscr->pages.size())
485 564400 sbpg = &sbscr->pages[pg];
486 282200 }
487 else return { nullptr, nullptr, nullptr, -1 }; //no subscreen
488
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 282200 times.
282200 if(sbpg)
489 {
490
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 282200 times.
282200 if(ind < sbpg->size())
491 564400 sbwidg = sbpg->at(ind);
492 282200 }
493 282200 return { sbscr, sbpg, sbwidg, ty };
494 282200 }
495 124905 std::pair<ZCSubscreen*,byte> load_subdata(dword ref)
496 {
497 124905 auto [sub,_pg,_widg,ty] = load_subscreen_ref(ref);
498 124905 return { sub, ty };
499 }
500 53553 std::pair<SubscrPage*,byte> load_subpage(dword ref)
501 {
502 53553 auto [_sub,pg,_widg,ty] = load_subscreen_ref(ref);
503 53553 return { pg, ty };
504 }
505 103742 std::pair<SubscrWidget*,byte> load_subwidg(dword ref)
506 {
507 103742 auto [_sub,_pg,widg,ty] = load_subscreen_ref(ref);
508 103742 return { widg, ty };
509 }
510
511 #include "zconsole/ConsoleLogger.h"
512
513 //no ifdef here
514 extern CConsoleLoggerEx zscript_coloured_console;
515
516 bool FFScript::isNumber(char chr)
517 {
518 if ( chr >= '0' )
519 {
520 if ( chr <= '9' ) return true;
521 }
522 return false;
523 }
524
525 int32_t FFScript::ilen(char *p)
526 {
527 int32_t ret = 0; int32_t pos = 0;
528 if(p[pos] == '-')
529 ret++;
530 for(; FFCore.isNumber(p[pos + ret]); ++ret);
531 return ret;
532 }
533
534 int32_t FFScript::atox(char *ip_str)
535 {
536 char tmp[2]={'2','\0'};
537 int32_t op_val=0, i=0, ip_len = strlen(ip_str);
538
539 if(strncmp(ip_str, "0x", 2) == 0)
540 {
541 ip_str +=2;
542 ip_len -=2;
543 }
544
545 for(i=0;i<ip_len;i++)
546 {
547 op_val *= 0x10;
548 switch(ip_str[i])
549 {
550 case 'a':
551 op_val += 0xa;
552 break;
553 case 'b':
554 op_val += 0xb;
555 break;
556 case 'c':
557 op_val += 0xc;
558 break;
559 case 'd':
560 op_val += 0xd;
561 break;
562 case 'e':
563 op_val += 0xe;
564 break;
565 case 'f':
566 op_val += 0xf;
567 break;
568 case '0':
569 case '1':
570 case '2':
571 case '3':
572 case '4':
573 case '5':
574 case '6':
575 case '7':
576 case '8':
577 case '9':
578 tmp[0] = ip_str[i];
579 op_val += atoi(tmp);
580 break;
581 default :
582 op_val += 0x0;
583 break;
584 }
585 }
586 return op_val;
587 }
588
589 char runningItemScripts[256] = {0};
590
591 //item *FFCore.temp_ff_item = NULL;
592 //enemy *FFCore.temp_ff_enemy = NULL;
593 //weapon *FFCore.temp_ff_lweapon = NULL;
594 //weapon *FFCore.temp_ff_eweapon = NULL;
595
596 extern int32_t directItemA;
597 extern int32_t directItemB;
598 extern int32_t directItemX;
599 extern int32_t directItemY;
600
601
602 #ifdef _MSC_VER
603 #pragma warning ( disable : 4800 ) //int32_t to bool town. population: lots.
604 #endif
605
606 #define NUMSHOPS 256
607 #define NUMINFOSHOPS 511
608
609 //! New datatype vars for 2.54:
610
611 //spritedata sp->member
612
613
614 using std::string;
615
616 extern char *guy_string[];
617 extern int32_t skipcont;
618
619 PALETTE tempgreypal; //Palettes go here. This is used for Greyscale() / Monochrome()
620 PALETTE userPALETTE[256]; //Palettes go here. This is used for Greyscale() / Monochrome()
621 PALETTE tempblackpal; //Used for storing the palette while fading to black
622
623 byte FF_hero_action; //This way, we can make safe replicas of internal Hero actions to be set by script.
624
625 int32_t FF_screenbounds[4]; //edges of the screen, left, right, top, bottom used for where to scroll.
626 int32_t FF_screen_dimensions[4]; //height, width, displaywidth, displayheight
627 int32_t FF_subscreen_dimensions[4];
628 int32_t FF_eweapon_removal_bounds[4]; //left, right, top, bottom coordinates for automatic eweapon removal.
629 int32_t FF_lweapon_removal_bounds[4]; //left, right, top, bottom coordinates for automatic lweapon removal.
630 int32_t FF_clocks[FFSCRIPTCLASS_CLOCKS]; //Will be used for Heroaction, anims, and so forth
631 byte ScriptDrawingRules[SCRIPT_DRAWING_RULES];
632 int32_t FF_UserMidis[NUM_USER_MIDI_OVERRIDES]; //MIDIs to use for Game Over, and similar to override system defaults.
633
634 int32_t get_int_arr(const int32_t ptr, int32_t indx);
635 void set_int_arr(const int32_t ptr, int32_t indx, int32_t val);
636 int32_t sz_int_arr(const int32_t ptr);
637
638 //We gain some speed by not passing as arguments
639 int32_t sarg1 = 0;
640 int32_t sarg2 = 0;
641 int32_t sarg3 = 0;
642 vector<int32_t> *sargvec;
643 string *sargstr;
644 refInfo *ri = NULL;
645 script_data *curscript = NULL;
646 int32_t(*stack)[MAX_SCRIPT_REGISTERS] = NULL;
647 bounded_vec<word, int32_t>* ret_stack;
648 vector<int32_t> zs_vargs;
649 ScriptType curScriptType;
650 word curScriptNum;
651 int32_t curScriptIndex;
652 bool script_funcrun = false;
653 string* destructstr = nullptr;
654 size_t gen_frozen_index = 0;
655
656 static vector<ScriptType> curScriptType_cache;
657 static vector<int32_t> curScriptNum_cache;
658 static vector<int32_t> curScriptIndex_cache;
659 static vector<int32_t> sarg1cache;
660 static vector<int32_t> sarg2cache;
661 static vector<int32_t> sarg3cache;
662 static vector<vector<int32_t>*> sargvec_cache;
663 static vector<string*> sargstr_cache;
664 static vector<refInfo*> ricache;
665 static vector<script_data*> sdcache;
666 static vector<int32_t(*)[MAX_SCRIPT_REGISTERS]> stackcache;
667 static vector<bounded_vec<word, int32_t>*> ret_stack_cache;
668 130 void push_ri()
669 {
670 130 sarg1cache.push_back(sarg1);
671 130 sarg2cache.push_back(sarg2);
672 130 sarg3cache.push_back(sarg3);
673 130 curScriptType_cache.push_back(curScriptType);
674 130 curScriptNum_cache.push_back(curScriptNum);
675 130 curScriptIndex_cache.push_back(curScriptIndex);
676 130 sargvec_cache.push_back(sargvec);
677 130 sargstr_cache.push_back(sargstr);
678 130 ricache.push_back(ri);
679 130 sdcache.push_back(curscript);
680 130 stackcache.push_back(stack);
681 130 ret_stack_cache.push_back(ret_stack);
682 130 }
683 130 void pop_ri()
684 {
685 130 sarg1 = sarg1cache.back(); sarg1cache.pop_back();
686 130 sarg2 = sarg2cache.back(); sarg2cache.pop_back();
687 130 sarg3 = sarg3cache.back(); sarg3cache.pop_back();
688 130 curScriptType = curScriptType_cache.back(); curScriptType_cache.pop_back();
689 130 curScriptNum = curScriptNum_cache.back(); curScriptNum_cache.pop_back();
690 130 curScriptIndex = curScriptIndex_cache.back(); curScriptIndex_cache.pop_back();
691 130 sargvec = sargvec_cache.back(); sargvec_cache.pop_back();
692 130 sargstr = sargstr_cache.back(); sargstr_cache.pop_back();
693 130 ri = ricache.back(); ricache.pop_back();
694 130 curscript = sdcache.back(); sdcache.pop_back();
695 130 stack = stackcache.back(); stackcache.pop_back();
696 130 ret_stack = ret_stack_cache.back(); ret_stack_cache.pop_back();
697 130 }
698
699 //START HELPER FUNCTIONS
700 ///-------------------------------------//
701 // Helper Functions //
702 ///-------------------------------------//
703
704 //only if the player is messing with their pointers...
705 ZScriptArray& SH::InvalidError(const int32_t ptr)
706 {
707 Z_scripterrlog("Invalid pointer (%i) passed to array (don't change the values of your array pointers)\n", ptr);
708 return INVALIDARRAY;
709 }
710
711 8935 void SH::write_stack(const uint32_t stackoffset, const int32_t value)
712 {
713
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8935 times.
8935 if(stackoffset >= MAX_SCRIPT_REGISTERS)
714 {
715 Z_scripterrlog("Stack over or underflow, stack pointer = %ld\n", stackoffset);
716 return;
717 }
718
719 8935 (*stack)[stackoffset] = value;
720 8935 }
721
722 758167018 int32_t SH::read_stack(const uint32_t stackoffset)
723 {
724
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 758167018 times.
758167018 if(stackoffset >= MAX_SCRIPT_REGISTERS)
725 {
726 Z_scripterrlog("Stack over or underflow, stack pointer = %ld\n", stackoffset);
727 return -10000;
728 }
729
730 758167018 return (*stack)[stackoffset];
731 758167018 }
732
733 ///----------------------------//
734 // Misc. //
735 ///----------------------------//
736
737 byte flagpos;
738 int32_t flagval;
739 21469831 void clear_ornextflag()
740 {
741 21469831 flagpos = 0;
742 21469831 flagval = 0;
743 21469831 }
744 145861533 void ornextflag(bool flag)
745 {
746
2/2
✓ Branch 0 taken 143700973 times.
✓ Branch 1 taken 2160560 times.
145861533 if(flag) flagval |= 1<<flagpos;
747 145861533 ++flagpos;
748 145861533 }
749
750 11161012 int32_t get_screenflags(mapscr *m, int32_t flagset)
751 {
752 11161012 clear_ornextflag();
753
754
5/11
✓ Branch 0 taken 4807572 times.
✓ Branch 1 taken 6263768 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 52 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 89609 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
11161012 switch(flagset)
755 {
756 case 0: // Room Type
757 4807572 ornextflag(m->flags6&1);
758 4807572 ornextflag(m->flags6&2);
759 4807572 ornextflag(m->flags7&8);
760 4807572 break;
761
762 case 1: // View
763 6263768 ornextflag(m->flags3&8);
764 6263768 ornextflag(m->flags7&16);
765 6263768 ornextflag(m->flags3&16);
766 6263768 ornextflag(m->flags3&64);
767 6263768 ornextflag(m->flags7&2);
768 6263768 ornextflag(m->flags7&1);
769 6263768 ornextflag(m->flags&fDARK);
770 6263768 ornextflag(m->flags9&fDARK_DITHER);
771 6263768 ornextflag(m->flags9&fDARK_TRANS);
772 6263768 break;
773
774 case 2: // Secrets
775 11 ornextflag(m->flags&1);
776 11 ornextflag(m->flags5&16);
777 11 ornextflag(m->flags6&4);
778 11 ornextflag(m->flags6&32);
779 11 break;
780
781 case 3: // Warp
782 ornextflag(m->flags5&4);
783 ornextflag(m->flags5&8);
784 ornextflag(m->flags&64);
785 ornextflag(m->flags8&64);
786 ornextflag(m->flags3&32);
787 ornextflag(m->flags9&fDISABLE_MIRROR);
788 ornextflag(m->flags10&fMAZE_CAN_GET_LOST);
789 ornextflag(m->flags10&fMAZE_LOOPY);
790 break;
791
792 case 4: // Item
793 52 ornextflag(m->flags3&1);
794 52 ornextflag(m->flags7&4);
795 52 ornextflag(m->flags8&0x40);
796 52 ornextflag(m->flags8&0x80);
797 52 ornextflag(m->flags9&0x01);
798 52 ornextflag(m->flags9&0x02);
799 52 ornextflag(m->flags9&fBELOWRETURN);
800 52 break;
801
802 case 5: // Combo
803 ornextflag((m->flags2>>4)&2);
804 ornextflag(m->flags3&2);
805 ornextflag(m->flags5&2);
806 ornextflag(m->flags6&64);
807 break;
808
809 case 6: // Save
810 ornextflag(m->flags4&64);
811 ornextflag(m->flags4&128);
812 ornextflag(m->flags6&8);
813 ornextflag(m->flags6&16);
814 break;
815
816 case 7: // FFC
817 ornextflag(m->flags6&128);
818 ornextflag(m->flags5&128);
819 break;
820
821 case 8: // Whistle
822 ornextflag(m->flags&16);
823 ornextflag(m->flags7&64);
824 ornextflag(m->flags7&128);
825 break;
826
827 case 9: // Misc
828 89609 ornextflag(m->flags&32);
829 89609 ornextflag(m->flags5&64);
830 89609 flagval |= m->flags8<<2;
831 89609 break;
832 }
833
834 11161012 return flagval*10000;
835 }
836
837 4473523 int32_t get_screeneflags(mapscr *m, int32_t flagset)
838 {
839 4473523 clear_ornextflag();
840
841
2/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4473221 times.
✓ Branch 3 taken 302 times.
4473523 switch(flagset)
842 {
843 case 0:
844 flagval |= m->flags11&0x1F;
845 break;
846
847 case 1:
848 4473221 ornextflag(m->flags11&32);
849 4473221 ornextflag(m->flags11&64);
850 4473221 ornextflag(m->flags3&4);
851 4473221 ornextflag(m->flags11&128);
852 4473221 ornextflag((m->flags2>>4)&4);
853 4473221 break;
854
855 case 2:
856 302 ornextflag(m->flags3&128);
857 302 ornextflag(m->flags&2);
858 302 ornextflag((m->flags2>>4)&8);
859 302 ornextflag(m->flags4&16);
860 302 ornextflag(m->flags9&fENEMY_WAVES);
861 302 break;
862 }
863
864 4473523 return flagval*10000;
865 }
866
867 45056 int32_t get_mi(int32_t ref)
868 {
869 45056 auto result = decode_mapdata_ref(ref);
870
1/2
✓ Branch 0 taken 45056 times.
✗ Branch 1 not taken.
45056 if (result.canonical())
871 {
872
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45056 times.
45056 if (result.screen >= MAPSCRSNORMAL) return -1;
873 45056 return mapind(result.scr->map, result.screen);
874 }
875 else if (result.current())
876 {
877 if (result.screen >= MAPSCRSNORMAL) return -1;
878 return mapind(cur_map, result.screen);
879 }
880 else if (result.scrolling())
881 {
882 if (result.screen >= MAPSCRSNORMAL) return -1;
883 return mapind(scrolling_map, result.screen);
884 }
885
886 return -1;
887 45056 }
888
889 int32_t get_ref_map_index(int32_t ref)
890 {
891 if (ref >= 0)
892 return ref;
893
894 auto result = decode_mapdata_ref(ref);
895 if (result.current())
896 {
897 return map_screen_index(cur_map, result.screen);
898 }
899 else if (result.scrolling())
900 {
901 return map_screen_index(scrolling_map, result.screen);
902 }
903
904 return -1;
905 }
906
907 template <typename T>
908 271106426 static T* ResolveSprite(int32_t uid, const char* name)
909 {
910
8/10
✓ Branch 0 taken 43115195 times.
✓ Branch 1 taken 966 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 162664718 times.
✓ Branch 5 taken 2612 times.
✓ Branch 6 taken 58765173 times.
✓ Branch 7 taken 183114 times.
✓ Branch 8 taken 6373774 times.
✓ Branch 9 taken 874 times.
271106426 if (!uid)
911 {
912
8/20
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 966 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 2612 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 2612 times.
✓ Branch 12 taken 183114 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 183114 times.
✓ Branch 16 taken 874 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 874 times.
187566 scripting_log_error_with_context("Invalid sprite: null pointer");
913 187566 return nullptr;
914 }
915
916
6/10
✗ Branch 0 not taken.
✓ Branch 1 taken 43115195 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 7108 times.
✓ Branch 5 taken 162657610 times.
✓ Branch 6 taken 20166 times.
✓ Branch 7 taken 58745007 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6373774 times.
270918860 if (auto s = sprite::getByUID(uid))
917 {
918
7/18
✗ Branch 0 not taken.
✓ Branch 1 taken 43115195 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 162657610 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 162657610 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 58745007 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 58745007 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 6373774 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 6373774 times.
270891586 if (auto s2 = dynamic_cast<T*>(s))
919 270891586 return s2;
920
921 scripting_log_error_with_context("Invalid sprite using UID = {} - but that sprite is not a {}", uid, name);
922 return nullptr;
923 }
924
925 27274 scripting_log_error_with_context("Invalid sprite using UID = {} - but that sprite does not exist", uid);
926 27274 return nullptr;
927 271106426 }
928
929 43116161 sprite* ResolveBaseSprite(int32_t uid)
930 {
931 43116161 return ResolveSprite<sprite>(uid, "sprite");
932 }
933
934 item* ResolveItemSprite(int32_t uid)
935 {
936 return ResolveSprite<item>(uid, "item");
937 }
938
939 162667318 enemy* ResolveNpc(int32_t uid)
940 {
941 162667318 return ResolveSprite<enemy>(uid, "npc");
942 }
943
944 static weapon* ResolveEWeapon_checkSpriteList(int32_t uid)
945 {
946 // Check here first (for the error logging.)
947 const char* name = "eweapon";
948 auto spr = ResolveSprite<weapon>(uid, name);
949
950 // Double check this is from the right sprite list.
951 if (spr && !Ewpns.getByUID(uid))
952 {
953 scripting_log_error_with_context("Invalid sprite using UID = {} - but that sprite is not a {}", uid, name);
954 return nullptr;
955 }
956
957 return spr;
958 }
959
960 598 static weapon* ResolveLWeapon_checkSpriteList(int32_t uid)
961 {
962 // Check here first (for the error logging.)
963 598 const char* name = "lweapon";
964 598 auto spr = ResolveSprite<weapon>(uid, name);
965
966 // Double check this is from the right sprite list.
967
2/4
✓ Branch 0 taken 598 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 598 times.
598 if (spr && !Lwpns.getByUID(uid))
968 {
969 scripting_log_error_with_context("Invalid sprite using UID = {} - but that sprite is not a {}", uid, name);
970 return nullptr;
971 }
972
973 598 return spr;
974 598 }
975
976 ///------------------------------------------------//
977 // Pointer Handling Functions //
978 ///------------------------------------------------//
979
980 //LWeapon Helper
981 class LwpnH : public SH
982 {
983
984 public:
985
986
987 static defWpnSprite getDefWeaponSprite(weapon *wp)
988 {
989 switch(wp->id)
990 {
991 case wNone: return ws_0;
992 case wSword: return ws_0;
993 case wBeam: return wsBeam;
994 case wBrang : return wsBrang;
995 case wBomb: return wsBomb;
996 case wSBomb: return wsSBomb;
997 case wLitBomb: return wsBombblast;
998 case wLitSBomb: return wsBombblast;
999 case wArrow: return wsArrow;
1000 case wRefArrow: return wsArrow;
1001 case wFire: return wsFire;
1002 case wRefFire: return wsFire;
1003 case wRefFire2: return wsFire;
1004 case wWhistle: return wsUnused45;
1005 case wBait: return wsBait;
1006 case wWand: return wsWandHandle;
1007 case wMagic: return wsMagic;
1008 case wCatching: return wsUnused45;
1009 case wWind: return wsWind;
1010 case wRefMagic: return wsRefMagic;
1011 case wRefFireball: return wsRefFireball;
1012 case wRefRock: return wsRock;
1013 case wHammer: return wsHammer;
1014 case wHookshot: return wsHookshotHead;
1015 case wHSHandle: return wsHookshotHandle;
1016 case wHSChain: return wsHookshotChainH;
1017 case wSSparkle: return wsSilverSparkle;
1018 case wFSparkle: return wsGoldSparkle;
1019 case wSmack: return wsHammerSmack;
1020 case wPhantom: return wsUnused45;
1021 case wCByrna: return wsByrnaCane;
1022 case wRefBeam: return wsRefBeam;
1023 case wStomp: return wsUnused45;
1024 case lwMax: return wsUnused45;
1025 case wScript1:
1026 case wScript2:
1027 case wScript3:
1028 case wScript4:
1029 case wScript5:
1030 case wScript6:
1031 case wScript7:
1032 case wScript8:
1033 case wScript9:
1034 case wScript10: return ws_0;
1035 case wIce: return wsIce; //new
1036 case wFlame: return wsEFire2; //new
1037 //not implemented; t/b/a
1038 case wSound:
1039 case wThrown:
1040 case wPot:
1041 case wLit:
1042 case wBombos:
1043 case wEther:
1044 case wQuake:
1045 case wSword180:
1046 case wSwordLA: return wsUnused45;
1047
1048 case ewFireball: return wsFireball2;
1049 case ewArrow: return wsEArrow;
1050 case ewBrang: return wsBrang;
1051 case ewSword: return wsEBeam;
1052 case ewRock: return wsRock;
1053 case ewMagic: return wsEMagic;
1054 case ewBomb: return wsEBomb;
1055 case ewSBomb: return wsESbomb;
1056 case ewLitBomb: return wsEBombblast;
1057 case ewLitSBomb: return wsESbombblast;
1058 case ewFireTrail: return wsEFiretrail;
1059 case ewFlame: return wsEFire;
1060 case ewWind: return wsEWind;
1061 case ewFlame2: return wsEFire2;
1062 case ewFlame2Trail: return wsEFiretrail2;
1063 case ewIce: return wsIce;
1064 case ewFireball2: return wsFireball2;
1065 default: return wsUnused45;
1066 }
1067 };
1068
1069 19653 static int32_t loadWeapon(const int32_t uid)
1070 {
1071 19653 tempweapon = ResolveSprite<weapon>(uid, "lweapon");
1072
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19653 times.
19653 if (!tempweapon)
1073 return _InvalidSpriteUID;
1074
1075 19653 return _NoError;
1076 19653 }
1077
1078 19653 static INLINE weapon *getWeapon()
1079 {
1080 19653 return tempweapon;
1081 }
1082
1083 35671 static INLINE void clearTemp()
1084 {
1085 35671 tempweapon = NULL;
1086 35671 }
1087
1088 private:
1089
1090 static weapon *tempweapon;
1091 };
1092
1093 weapon *LwpnH::tempweapon = NULL;
1094
1095 //EWeapon Helper
1096 class EwpnH : public SH
1097 {
1098
1099 public:
1100
1101 defWpnSprite getDefWeaponSprite(weapon *wp)
1102 {
1103 switch(wp->id)
1104 {
1105 case wNone: return ws_0;
1106 case wSword: return ws_0;
1107 case wBeam: return wsBeam;
1108 case wBrang : return wsBrang;
1109 case wBomb: return wsBomb;
1110 case wSBomb: return wsSBomb;
1111 case wLitBomb: return wsBombblast;
1112 case wLitSBomb: return wsBombblast;
1113 case wArrow: return wsArrow;
1114 case wRefArrow: return wsArrow;
1115 case wFire: return wsFire;
1116 case wRefFire: return wsFire;
1117 case wRefFire2: return wsFire;
1118 case wWhistle: return wsUnused45;
1119 case wBait: return wsBait;
1120 case wWand: return wsWandHandle;
1121 case wMagic: return wsMagic;
1122 case wCatching: return wsUnused45;
1123 case wWind: return wsWind;
1124 case wRefMagic: return wsRefMagic;
1125 case wRefFireball: return wsRefFireball;
1126 case wRefRock: return wsRock;
1127 case wHammer: return wsHammer;
1128 case wHookshot: return wsHookshotHead;
1129 case wHSHandle: return wsHookshotHandle;
1130 case wHSChain: return wsHookshotChainH;
1131 case wSSparkle: return wsSilverSparkle;
1132 case wFSparkle: return wsGoldSparkle;
1133 case wSmack: return wsHammerSmack;
1134 case wPhantom: return wsUnused45;
1135 case wCByrna: return wsByrnaCane;
1136 case wRefBeam: return wsRefBeam;
1137 case wStomp: return wsUnused45;
1138 case lwMax: return wsUnused45;
1139 case wScript1:
1140 case wScript2:
1141 case wScript3:
1142 case wScript4:
1143 case wScript5:
1144 case wScript6:
1145 case wScript7:
1146 case wScript8:
1147 case wScript9:
1148 case wScript10: return ws_0;
1149 case wIce: return wsIce; //new
1150 case wFlame: return wsEFire2; //new
1151 //not implemented; t/b/a
1152 case wSound:
1153 case wThrown:
1154 case wPot:
1155 case wLit:
1156 case wBombos:
1157 case wEther:
1158 case wQuake:
1159 case wSword180:
1160 case wSwordLA: return wsUnused45;
1161
1162 case ewFireball: return wsFireball2;
1163 case ewArrow: return wsEArrow;
1164 case ewBrang: return wsBrang;
1165 case ewSword: return wsEBeam;
1166 case ewRock: return wsRock;
1167 case ewMagic: return wsEMagic;
1168 case ewBomb: return wsEBomb;
1169 case ewSBomb: return wsESbomb;
1170 case ewLitBomb: return wsEBombblast;
1171 case ewLitSBomb: return wsESbombblast;
1172 case ewFireTrail: return wsEFiretrail;
1173 case ewFlame: return wsEFire;
1174 case ewWind: return wsEWind;
1175 case ewFlame2: return wsEFire2;
1176 case ewFlame2Trail: return wsEFiretrail2;
1177 case ewIce: return wsIce;
1178 case ewFireball2: return wsFireball2;
1179 default: return wsUnused45;
1180 }
1181 };
1182
1183 208946 static int32_t loadWeapon(const int32_t uid)
1184 {
1185 208946 tempweapon = ResolveSprite<weapon>(uid, "eweapon");
1186
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 208946 times.
208946 if (!tempweapon)
1187 return _InvalidSpriteUID;
1188
1189 208946 return _NoError;
1190 208946 }
1191
1192 208946 static INLINE weapon *getWeapon()
1193 {
1194 208946 return tempweapon;
1195 }
1196
1197 35671 static INLINE void clearTemp()
1198 {
1199 35671 tempweapon = NULL;
1200 35671 }
1201
1202 private:
1203
1204 static weapon *tempweapon;
1205 };
1206
1207 weapon *EwpnH::tempweapon = NULL;
1208
1209 35671 void clearScriptHelperData()
1210 {
1211 35671 GuyH::clearTemp();
1212 35671 LwpnH::clearTemp();
1213 35671 EwpnH::clearTemp();
1214 35671 ItemH::clearTemp();
1215 35671 }
1216 ////END HELPER FUNCTIONS
1217
1218 static int32_t numInstructions = 0; // Used to detect hangs
1219 static bool scriptCanSave = true;
1220
1221 692261205 static ScriptEngineData& get_script_engine_data(ScriptType type, int index)
1222 {
1223
8/8
✓ Branch 0 taken 659922628 times.
✓ Branch 1 taken 32338577 times.
✓ Branch 2 taken 659919283 times.
✓ Branch 3 taken 3345 times.
✓ Branch 4 taken 627713547 times.
✓ Branch 5 taken 32205736 times.
✓ Branch 6 taken 17798 times.
✓ Branch 7 taken 627695749 times.
692261205 if (type == ScriptType::DMap || type == ScriptType::OnMap || type == ScriptType::ScriptedPassiveSubscreen || type == ScriptType::ScriptedActiveSubscreen)
1224 {
1225 // `index` is used for dmapref, not for different script engine data.
1226 64565456 index = 0;
1227 64565456 }
1228
2/2
✓ Branch 0 taken 692200349 times.
✓ Branch 1 taken 60856 times.
692261205 if (type == ScriptType::EngineSubscreen)
1229 {
1230 // `index` is used for subdataref, not for different script engine data.
1231 60856 index = 0;
1232 60856 }
1233
1234 692261205 return scriptEngineDatas[{type, index}];
1235 }
1236
1237 975663 static bool script_engine_data_exists(ScriptType type, int index)
1238 {
1239
5/8
✓ Branch 0 taken 972385 times.
✓ Branch 1 taken 3278 times.
✓ Branch 2 taken 972385 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 972385 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 972385 times.
975663 if (type == ScriptType::DMap || type == ScriptType::OnMap || type == ScriptType::ScriptedPassiveSubscreen || type == ScriptType::ScriptedActiveSubscreen)
1240 {
1241 // `index` is used for dmapref, not for different script engine data.
1242 3278 index = 0;
1243 3278 }
1244
1/2
✓ Branch 0 taken 975663 times.
✗ Branch 1 not taken.
975663 if (type == ScriptType::EngineSubscreen)
1245 {
1246 // `index` is used for subdataref, not for different script engine data.
1247 index = 0;
1248 }
1249
1250 975663 return scriptEngineDatas.contains({type, index});
1251 }
1252
1253 46 static ScriptEngineData& get_script_engine_data(ScriptType type)
1254 {
1255 46 return get_script_engine_data(type, 0);
1256 }
1257
1258 1094 void FFScript::clear_script_engine_data()
1259 {
1260 1094 scriptEngineDatas.clear();
1261 1094 }
1262
1263 1132823 void FFScript::reset_script_engine_data(ScriptType type, int index)
1264 {
1265 1132823 get_script_engine_data(type, index).reset();
1266 1132823 }
1267
1268 80964 void on_reassign_script_engine_data(ScriptType type, int index)
1269 {
1270 80964 auto& data = get_script_engine_data(type, index);
1271 80964 data.ref.Clear();
1272 80964 data.initialized = false;
1273 80964 FFScript::deallocateAllScriptOwned(type, index);
1274 80964 }
1275
1276 1325682 void FFScript::clear_script_engine_data(ScriptType type, int index)
1277 {
1278
4/8
✓ Branch 0 taken 1325682 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1325682 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1325682 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1325682 times.
1325682 if (type == ScriptType::DMap || type == ScriptType::OnMap || type == ScriptType::ScriptedPassiveSubscreen || type == ScriptType::ScriptedActiveSubscreen)
1279 {
1280 // `index` is used for dmapref, not for different script engine data.
1281 index = 0;
1282 }
1283
1/2
✓ Branch 0 taken 1325682 times.
✗ Branch 1 not taken.
1325682 if (type == ScriptType::EngineSubscreen)
1284 {
1285 // `index` is used for subdataref, not for different script engine data.
1286 index = 0;
1287 }
1288
1289 1325682 auto it = scriptEngineDatas.find({type, index});
1290
2/2
✓ Branch 0 taken 1325045 times.
✓ Branch 1 taken 637 times.
1325682 if (it != scriptEngineDatas.end())
1291 {
1292 637 scriptEngineDatas.erase(it);
1293 637 }
1294 1325682 }
1295
1296 134388 void FFScript::clear_script_engine_data_of_type(ScriptType type)
1297 {
1298 76296689 std::erase_if(scriptEngineDatas, [&](auto& kv) { return kv.first.first == type; });
1299 134388 }
1300
1301 307 refInfo& FFScript::ref(ScriptType type, int index)
1302 {
1303 307 return get_script_engine_data(type, index).ref;
1304 }
1305
1306 64404207 byte& FFScript::doscript(ScriptType type, int index)
1307 {
1308
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 64404207 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
64404207 if (type == ScriptType::Generic && unsigned(index) < NUMSCRIPTSGENERIC)
1309 return user_genscript::get(index).doscript();
1310 64404207 return get_script_engine_data(type, index).doscript;
1311 64404207 }
1312
1313 526886777 bool& FFScript::waitdraw(ScriptType type, int index)
1314 {
1315 526886777 return get_script_engine_data(type, index).waitdraw;
1316 }
1317
1318 // Returns true if registers had to be initialized.
1319 26668558 static bool set_current_script_engine_data(ScriptType type, int script, int index)
1320 {
1321 26668558 bool got_initialized = false;
1322
1323 26668558 auto& data = get_script_engine_data(type, index);
1324 26668558 ri = &data.ref;
1325 26668558 stack = &data.stack;
1326 26668558 ret_stack = &data.ret_stack;
1327
1328 // By default, make `Screen->` refer to the top-left screen.
1329 // Will be set to something more specific for relevant script types.
1330 26668558 ri->screenref = cur_screen;
1331
1332
16/18
✗ Branch 0 not taken.
✓ Branch 1 taken 212924 times.
✓ Branch 2 taken 147334 times.
✓ Branch 3 taken 7460 times.
✓ Branch 4 taken 11112510 times.
✓ Branch 5 taken 1542 times.
✓ Branch 6 taken 74176 times.
✓ Branch 7 taken 114 times.
✓ Branch 8 taken 12244 times.
✓ Branch 9 taken 1402 times.
✓ Branch 10 taken 15162 times.
✓ Branch 11 taken 56311 times.
✓ Branch 12 taken 368512 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 11172226 times.
✓ Branch 15 taken 15539 times.
✓ Branch 16 taken 2140773 times.
✓ Branch 17 taken 1330329 times.
26668558 switch (type)
1333 {
1334 case ScriptType::FFC:
1335 {
1336 11172226 curscript = ffscripts[script];
1337 11172226 ffcdata* ffc = get_ffc(index);
1338
1339
2/2
✓ Branch 0 taken 11145571 times.
✓ Branch 1 taken 26655 times.
11172226 if (!data.initialized)
1340 {
1341 26655 got_initialized = true;
1342 26655 mapscr* scr = get_scr(ffc->screen_spawned);
1343 26655 memcpy(ri->d, scr->ffcs[index % 128].initd, 8 * sizeof(int32_t));
1344 26655 data.initialized = true;
1345 26655 }
1346
1347
2/2
✓ Branch 0 taken 1644354 times.
✓ Branch 1 taken 9527872 times.
11172226 ri->ffcref = ZScriptVersion::ffcRefIsSpriteId() ? ffc->getUID() : index;
1348 11172226 ri->screenref = ffc->screen_spawned;
1349 }
1350 11172226 break;
1351
1352 case ScriptType::NPC:
1353 {
1354 enemy *spr = (enemy*)guys.getByUID(index);
1355 curscript = guyscripts[script];
1356
1357 if (!data.initialized)
1358 {
1359 got_initialized = true;
1360 memcpy(ri->d, spr->initD, 8 * sizeof(int32_t));
1361 data.initialized = 1;
1362 }
1363
1364 ri->guyref = index;
1365 ri->screenref = spr->screen_spawned;
1366 }
1367 break;
1368
1369 case ScriptType::Lwpn:
1370 {
1371 212924 weapon *spr = (weapon*)Lwpns.getByUID(index);
1372 212924 curscript = lwpnscripts[script];
1373
1374
2/2
✓ Branch 0 taken 150555 times.
✓ Branch 1 taken 62369 times.
212924 if (!data.initialized)
1375 {
1376 62369 got_initialized = true;
1377 62369 memcpy(ri->d, spr->weap_initd, 8 * sizeof(int32_t));
1378 62369 data.initialized = 1;
1379 62369 }
1380
1381 212924 ri->lwpn = index;
1382 212924 ri->screenref = spr->screen_spawned;
1383 }
1384 212924 break;
1385
1386 case ScriptType::Ewpn:
1387 {
1388 147334 weapon *spr = (weapon*)Ewpns.getByUID(index);
1389 147334 curscript = ewpnscripts[script];
1390
1391
2/2
✓ Branch 0 taken 145713 times.
✓ Branch 1 taken 1621 times.
147334 if (!data.initialized)
1392 {
1393 1621 got_initialized = true;
1394 1621 memcpy(ri->d, spr->weap_initd, 8 * sizeof(int32_t));
1395 1621 data.initialized = 1;
1396 1621 }
1397
1398 147334 ri->ewpn = index;
1399 147334 ri->screenref = spr->screen_spawned;
1400 }
1401 147334 break;
1402
1403 case ScriptType::ItemSprite:
1404 {
1405 7460 item *spr = (item*)items.getByUID(index);
1406 7460 curscript = itemspritescripts[script];
1407
1408
2/2
✓ Branch 0 taken 7210 times.
✓ Branch 1 taken 250 times.
7460 if (!data.initialized)
1409 {
1410 250 got_initialized = true;
1411 250 memcpy(ri->d, spr->initD, 8 * sizeof(int32_t));
1412 250 data.initialized = 1;
1413 250 }
1414
1415 7460 ri->itemref = index;
1416 7460 ri->screenref = spr->screen_spawned;
1417 }
1418 7460 break;
1419
1420 case ScriptType::Item:
1421 {
1422 15539 int32_t i = index;
1423 15539 int32_t new_i = 0;
1424
2/2
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 15232 times.
15539 bool collect = ( ( i < 1 ) || (i == COLLECT_SCRIPT_ITEM_ZERO) );
1425
3/4
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 15232 times.
✓ Branch 2 taken 307 times.
✗ Branch 3 not taken.
15539 new_i = ( collect ) ? (( i != COLLECT_SCRIPT_ITEM_ZERO ) ? (i * -1) : 0) : i;
1426
1427 15539 curscript = itemscripts[script];
1428
1429
2/2
✓ Branch 0 taken 13490 times.
✓ Branch 1 taken 2049 times.
15539 if (!data.initialized)
1430 {
1431 2049 got_initialized = true;
1432
2/2
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 1742 times.
2049 memcpy(ri->d, ( collect ) ? itemsbuf[new_i].initiald : itemsbuf[i].initiald, 8 * sizeof(int32_t));
1433 2049 data.initialized = true;
1434 2049 }
1435
2/2
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 15232 times.
15539 ri->idata = ( collect ) ? new_i : i; //'this' pointer
1436 }
1437 15539 break;
1438
1439 case ScriptType::Global:
1440 {
1441 11112510 curscript = globalscripts[script];
1442
2/2
✓ Branch 0 taken 11109402 times.
✓ Branch 1 taken 3108 times.
11112510 if (!data.initialized)
1443 {
1444 3108 got_initialized = true;
1445 3108 data.initialized = 1;
1446 3108 }
1447 }
1448 11112510 break;
1449
1450 case ScriptType::Generic:
1451 {
1452 2140773 user_genscript& scr = user_genscript::get(script);
1453 2140773 curscript = genericscripts[script];
1454 2140773 scr.waitevent = false;
1455
2/2
✓ Branch 0 taken 2140198 times.
✓ Branch 1 taken 575 times.
2140773 if(!data.initialized)
1456 {
1457 575 got_initialized = true;
1458 575 scr.initd.copy_to(ri->d, 8);
1459 575 data.initialized = true;
1460 575 }
1461 2140773 ri->genericdataref = script;
1462 }
1463 2140773 break;
1464
1465 case ScriptType::GenericFrozen:
1466 {
1467 1542 user_genscript& scr = user_genscript::get(script);
1468 1542 curscript = genericscripts[script];
1469
2/2
✓ Branch 0 taken 1532 times.
✓ Branch 1 taken 10 times.
1542 if(!data.initialized)
1470 {
1471 10 got_initialized = true;
1472 10 scr.initd.copy_to(ri->d, 8);
1473 10 data.initialized = true;
1474 10 }
1475 1542 ri->genericdataref = script;
1476 }
1477 1542 break;
1478
1479 case ScriptType::Hero:
1480 {
1481 1330329 curscript = playerscripts[script];
1482 1330329 ri->screenref = hero_screen;
1483
2/2
✓ Branch 0 taken 1329874 times.
✓ Branch 1 taken 455 times.
1330329 if (!data.initialized)
1484 {
1485 455 got_initialized = true;
1486 455 data.initialized = 1;
1487 455 }
1488 }
1489 1330329 break;
1490
1491 case ScriptType::DMap:
1492 {
1493 74176 curscript = dmapscripts[script];
1494 74176 ri->dmapsref = index;
1495 //how do we clear initialised on dmap change?
1496
2/2
✓ Branch 0 taken 74087 times.
✓ Branch 1 taken 89 times.
74176 if ( !data.initialized )
1497 {
1498 89 got_initialized = true;
1499
2/2
✓ Branch 0 taken 712 times.
✓ Branch 1 taken 89 times.
801 for ( int32_t q = 0; q < 8; q++ )
1500 {
1501 712 ri->d[q] = DMaps[ri->dmapsref].initD[q];// * 10000;
1502 712 }
1503 89 data.initialized = true;
1504 89 }
1505 }
1506 74176 break;
1507
1508 case ScriptType::OnMap:
1509 {
1510 114 curscript = dmapscripts[script];
1511 114 ri->dmapsref = index;
1512
2/2
✓ Branch 0 taken 111 times.
✓ Branch 1 taken 3 times.
114 if (!data.initialized)
1513 {
1514 3 got_initialized = true;
1515
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 3 times.
27 for ( int32_t q = 0; q < 8; q++ )
1516 {
1517 24 ri->d[q] = DMaps[ri->dmapsref].onmap_initD[q];
1518 24 }
1519 3 data.initialized = true;
1520 3 }
1521 }
1522 114 break;
1523
1524 case ScriptType::ScriptedActiveSubscreen:
1525 {
1526 12244 curscript = dmapscripts[script];
1527 12244 ri->dmapsref = index;
1528
2/2
✓ Branch 0 taken 12203 times.
✓ Branch 1 taken 41 times.
12244 if (!data.initialized)
1529 {
1530 41 got_initialized = true;
1531
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 41 times.
369 for ( int32_t q = 0; q < 8; q++ )
1532 {
1533 328 ri->d[q] = DMaps[ri->dmapsref].sub_initD[q];
1534 328 }
1535 41 data.initialized = true;
1536 41 }
1537 }
1538 12244 break;
1539
1540 case ScriptType::ScriptedPassiveSubscreen:
1541 {
1542 1402 curscript = dmapscripts[script];
1543 1402 ri->dmapsref = index;
1544
2/2
✓ Branch 0 taken 1400 times.
✓ Branch 1 taken 2 times.
1402 if (!data.initialized)
1545 {
1546 2 got_initialized = true;
1547
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 2 times.
18 for ( int32_t q = 0; q < 8; q++ )
1548 {
1549 16 ri->d[q] = DMaps[ri->dmapsref].sub_initD[q];
1550 16 }
1551 2 data.initialized = true;
1552 2 }
1553 }
1554 1402 break;
1555 case ScriptType::EngineSubscreen:
1556 {
1557 15162 curscript = subscreenscripts[script];
1558 15162 ri->subdataref = get_subref(-1, sstACTIVE);
1559 15450 auto [ptr,_ty] = load_subdata(ri->subdataref);
1560
1561
3/4
✓ Branch 0 taken 15162 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15126 times.
✓ Branch 3 taken 36 times.
15162 if (ptr && !data.initialized)
1562 {
1563 36 got_initialized = true;
1564
2/2
✓ Branch 0 taken 288 times.
✓ Branch 1 taken 36 times.
324 for ( int32_t q = 0; q < 8; q++ )
1565 {
1566 288 ri->d[q] = ptr->initd[q];
1567 288 }
1568 36 data.initialized = true;
1569 36 }
1570 }
1571 15162 break;
1572
1573 case ScriptType::Screen:
1574 {
1575 56311 curscript = screenscripts[script];
1576
1577
2/2
✓ Branch 0 taken 56192 times.
✓ Branch 1 taken 119 times.
56311 if (!data.initialized)
1578 {
1579 119 got_initialized = true;
1580 119 mapscr* scr = get_scr(index);
1581
2/2
✓ Branch 0 taken 952 times.
✓ Branch 1 taken 119 times.
1071 for ( int32_t q = 0; q < 8; q++ )
1582 {
1583 952 ri->d[q] = scr->screeninitd[q];// * 10000;
1584 952 }
1585 119 data.initialized = true;
1586 119 }
1587
1588 56311 ri->screenref = index;
1589 }
1590 56311 break;
1591
1592 case ScriptType::Combo:
1593 {
1594 368512 curscript = comboscripts[script];
1595
1596 368512 rpos_t rpos = combopos_ref_to_rpos(index);
1597 368512 int32_t lyr = combopos_ref_to_layer(index);
1598 368512 auto rpos_handle = get_rpos_handle(rpos, lyr);
1599 368512 int32_t id = rpos_handle.data();
1600
2/2
✓ Branch 0 taken 360187 times.
✓ Branch 1 taken 8325 times.
368512 if (!data.initialized)
1601 {
1602 8325 got_initialized = true;
1603 8325 memset(ri->d, 0, 8 * sizeof(int32_t));
1604
2/2
✓ Branch 0 taken 66600 times.
✓ Branch 1 taken 8325 times.
74925 for ( int32_t q = 0; q < 8; q++ )
1605 66600 ri->d[q] = combobuf[id].initd[q];
1606 8325 data.initialized = true;
1607 8325 }
1608
1609 368512 ri->combosref = id; //'this' pointer
1610 368512 ri->comboposref = index; //used for X(), Y(), Layer(), and so forth.
1611 368512 ri->screenref = rpos_handle.screen;
1612 368512 break;
1613 }
1614 }
1615
1616
2/2
✓ Branch 0 taken 26562851 times.
✓ Branch 1 taken 105707 times.
26668558 if (got_initialized)
1617 105707 ri->pc = curscript->pc;
1618
1619 26668558 return got_initialized;
1620 }
1621
1622 643317972 static ffcdata *ResolveFFCWithID(ffc_id_t id)
1623 {
1624
2/2
✓ Branch 0 taken 231 times.
✓ Branch 1 taken 643317741 times.
643317972 if (BC::checkFFC(id) != SH::_NoError)
1625 231 return nullptr;
1626
1627 643317741 ffcdata* ffc = get_ffc(id);
1628
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 643317741 times.
643317741 if (!ffc)
1629 scripting_log_error_with_context("Invalid ffc using ID = {}", id);
1630
1631 643317741 return ffc;
1632 643317972 }
1633
1634 646324090 static ffcdata *ResolveFFC(int32_t ffcref)
1635 {
1636
2/2
✓ Branch 0 taken 6374648 times.
✓ Branch 1 taken 639949442 times.
646324090 if (ZScriptVersion::ffcRefIsSpriteId())
1637 6374648 return ResolveSprite<ffcdata>(ffcref, "ffc");
1638
1639 639949442 return ResolveFFCWithID(ffcref);
1640 646324090 }
1641
1642 46056 static mapscr* ResolveMapdata(int32_t mapref)
1643 {
1644 46056 auto result = decode_mapdata_ref(mapref);
1645
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46056 times.
46056 if (!result.scr)
1646 scripting_log_error_with_context("mapdata id is invalid: {}", mapref);
1647 46056 return result.scr;
1648 }
1649
1650 86700881 static rpos_handle_t ResolveMapdataPos(int32_t mapref, int pos)
1651 {
1652 86700881 auto result = decode_mapdata_ref(mapref);
1653
1/2
✓ Branch 0 taken 86700881 times.
✗ Branch 1 not taken.
86700881 if (!result.scr)
1654 {
1655 scripting_log_error_with_context("mapdata id is invalid: {}", mapref);
1656 return rpos_handle_t{};
1657 }
1658
1659
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 86700881 times.
86700881 if (result.scrolling())
1660 {
1661 scripting_log_error_with_context("mapdata id is invalid: {} - screen is not scrolling right now", mapref);
1662 return rpos_handle_t{};
1663 }
1664
1665 // mapdata loaded via `Game->LoadTempScreen(layer)` have access to the entire region.
1666
2/2
✓ Branch 0 taken 69348879 times.
✓ Branch 1 taken 17352002 times.
86700881 if (result.type == mapdata_type::TemporaryCurrentRegion)
1667 {
1668 69348879 rpos_t rpos = (rpos_t)pos;
1669
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69348879 times.
69348879 if (BC::checkComboRpos(rpos) != SH::_NoError)
1670 return rpos_handle_t{};
1671
1672 69348879 return get_rpos_handle(rpos, result.layer);
1673 }
1674
1675 // mapdata loaded via `Game->LoadScrollingScreen(layer)` have access to the entire scrolling region.
1676
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17352002 times.
17352002 if (result.type == mapdata_type::TemporaryScrollingScreen)
1677 {
1678 rpos_t rpos = (rpos_t)pos;
1679 rpos_t max = (rpos_t)(scrolling_region.screen_count * 176 - 1);
1680 if (BC::checkBoundsRpos(rpos, (rpos_t)0, max) != SH::_NoError)
1681 return rpos_handle_t{};
1682
1683 int origin_screen = scrolling_region.origin_screen;
1684 int origin_screen_x = origin_screen % 16;
1685 int origin_screen_y = origin_screen / 16;
1686 int scr_index = static_cast<int32_t>(rpos) / 176;
1687 int scr_x = origin_screen_x + scr_index%cur_region.screen_width;
1688 int scr_y = origin_screen_y + scr_index/cur_region.screen_width;
1689 int screen = map_scr_xy_to_index(scr_x, scr_y);
1690 mapscr* scr = FFCore.ScrollingScreensAll[screen * 7 + result.layer];
1691
1692 return {scr, screen, result.layer, rpos, RPOS_TO_POS(rpos)};
1693 }
1694
1695 // Otherwise, access is limited to just one screen.
1696
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17352002 times.
17352002 if (BC::checkComboPos(pos) != SH::_NoError)
1697 return rpos_handle_t{};
1698
1699
1/2
✓ Branch 0 taken 17352002 times.
✗ Branch 1 not taken.
17352002 if (result.type == mapdata_type::CanonicalScreen)
1700 17352002 return {result.scr, result.screen, 0, (rpos_t)pos, pos};
1701
1702 if (result.scrolling())
1703 {
1704 if (!result.scr->is_valid())
1705 return rpos_handle_t{};
1706
1707 return {result.scr, result.screen, result.layer, (rpos_t)pos, pos};
1708 }
1709
1710 rpos_t rpos = POS_TO_RPOS(pos, result.screen);
1711 if (BC::checkComboRpos(rpos) != SH::_NoError)
1712 return rpos_handle_t{};
1713
1714 return {result.scr, result.screen, result.layer, rpos, pos};
1715 86700881 }
1716
1717 1559638 static ffc_handle_t ResolveMapdataFFC(int32_t mapref, int index)
1718 {
1719 1559638 index -= 1;
1720
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1559638 times.
1559638 if (BC::checkMapdataFFC(index) != SH::_NoError)
1721 return ffc_handle_t{};
1722
1723 1559638 auto result = decode_mapdata_ref(mapref);
1724
1/2
✓ Branch 0 taken 1559638 times.
✗ Branch 1 not taken.
1559638 if (!result.scr)
1725 {
1726 scripting_log_error_with_context("mapdata id is invalid: {}", mapref);
1727 return ffc_handle_t{};
1728 }
1729
1730 1559638 int screen_index_offset = 0;
1731
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1559638 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1559638 if (result.current() && result.layer == 0)
1732 screen_index_offset = get_region_screen_offset(result.screen);
1733
1734 1559638 return *result.scr->getFFCHandle(index, screen_index_offset);
1735 1559638 }
1736
1737 int32_t genscript_timing = SCR_TIMING_START_FRAME;
1738 static word max_valid_genscript;
1739
1740 211456 void user_genscript::clear()
1741 {
1742 211456 wait_atleast = true;
1743 211456 waituntil = SCR_TIMING_START_FRAME;
1744 211456 waitevent = false;
1745 211456 exitState = 0;
1746 211456 reloadState = 0;
1747 211456 eventstate = 0;
1748 211456 initd.clear();
1749 211456 data.clear();
1750 211456 quit();
1751 211456 }
1752 526 void user_genscript::launch()
1753 {
1754 526 quit();
1755 526 doscript() = true;
1756 526 wait_atleast = true;
1757 526 waituntil = SCR_TIMING_START_FRAME;
1758 526 waitevent = false;
1759 526 }
1760 212016 void user_genscript::quit()
1761 {
1762
1/2
✓ Branch 0 taken 212016 times.
✗ Branch 1 not taken.
212016 if(indx > -1)
1763 {
1764 212016 FFCore.clear_script_engine_data(ScriptType::Generic, indx);
1765 212016 FFCore.deallocateAllScriptOwned(ScriptType::Generic, indx);
1766 212016 }
1767 212016 _doscript = false;
1768 212016 }
1769 255945239 byte& user_genscript::doscript()
1770 {
1771 255945239 return _doscript;
1772 }
1773 512 byte const& user_genscript::doscript() const
1774 {
1775 512 return _doscript;
1776 }
1777
1778
1779 268695629 user_genscript& user_genscript::get(int ind)
1780 {
1781
3/4
✓ Branch 0 taken 268695215 times.
✓ Branch 1 taken 414 times.
✓ Branch 2 taken 268695215 times.
✗ Branch 3 not taken.
268695629 if(ind < 1 || ind >= NUMSCRIPTSGENERIC)
1782 414 ind = 0;
1783 268695629 user_scripts[ind].indx = ind;
1784 268695629 return user_scripts[ind];
1785 }
1786
3/4
✓ Branch 0 taken 206336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 205933 times.
✓ Branch 3 taken 403 times.
206336 user_genscript user_genscript::user_scripts[NUMSCRIPTSGENERIC];
1787
1788 1507 void countGenScripts()
1789 {
1790 1507 max_valid_genscript = 0;
1791
2/2
✓ Branch 0 taken 770077 times.
✓ Branch 1 taken 1507 times.
771584 for(auto q = 1; q < NUMSCRIPTSGENERIC; ++q)
1792 {
1793
3/4
✓ Branch 0 taken 770077 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 767104 times.
✓ Branch 3 taken 2973 times.
770077 if(genericscripts[q] && genericscripts[q]->valid())
1794 2973 max_valid_genscript = q;
1795 770077 }
1796 1507 }
1797 44037 void timeExitAllGenscript(byte exState)
1798 {
1799
2/2
✓ Branch 0 taken 25624 times.
✓ Branch 1 taken 44037 times.
69661 for(auto q = 1; q <= max_valid_genscript; ++q)
1800 25624 user_genscript::get(q).timeExit(exState);
1801 44037 }
1802 469574 void throwGenScriptEvent(int32_t event)
1803 {
1804
2/2
✓ Branch 0 taken 133438 times.
✓ Branch 1 taken 469574 times.
603012 for(auto q = 1; q <= max_valid_genscript; ++q)
1805 {
1806 133438 user_genscript& scr = user_genscript::get(q);
1807
2/2
✓ Branch 0 taken 76759 times.
✓ Branch 1 taken 56679 times.
133438 if(!scr.doscript()) continue;
1808
2/2
✓ Branch 0 taken 73959 times.
✓ Branch 1 taken 2800 times.
76759 if(!genericscripts[q]->valid()) continue;
1809
2/2
✓ Branch 0 taken 41495 times.
✓ Branch 1 taken 32464 times.
73959 if(!scr.waitevent) continue;
1810
2/2
✓ Branch 0 taken 3068 times.
✓ Branch 1 taken 38427 times.
41495 if(scr.eventstate & (1<<event))
1811 {
1812 3068 auto& data = get_script_engine_data(ScriptType::Generic, q);
1813 3068 data.ref.d[rEXP1] = event*10000;
1814 3068 scr.waitevent = false;
1815
1816 //Run the script!
1817 3068 ZScriptVersion::RunScript(ScriptType::Generic, q, q);
1818 3068 }
1819 41495 }
1820 469574 }
1821
1822 214 void load_genscript(const gamedata& gd)
1823 {
1824
2/2
✓ Branch 0 taken 109568 times.
✓ Branch 1 taken 214 times.
109782 for(size_t q = 0; q < NUMSCRIPTSGENERIC; ++q)
1825 {
1826 109568 user_genscript& gen = user_genscript::get(q);
1827 109568 gen.clear();
1828 109568 gen.doscript() = gd.gen_doscript.get(q);
1829 109568 gen.exitState = gd.gen_exitState[q];
1830 109568 gen.reloadState = gd.gen_reloadState[q];
1831 109568 gen.eventstate = gd.gen_eventstate[q];
1832 109568 gen.initd = gd.gen_initd[q];
1833 109568 gen.data = gd.gen_data[q];
1834 109568 }
1835 214 }
1836 199 void load_genscript(const zinitdata& zd)
1837 {
1838
2/2
✓ Branch 0 taken 101888 times.
✓ Branch 1 taken 199 times.
102087 for(size_t q = 0; q < NUMSCRIPTSGENERIC; ++q)
1839 {
1840 101888 user_genscript& gen = user_genscript::get(q);
1841 101888 gen.clear();
1842 101888 gen.doscript() = zd.gen_doscript.get(q);
1843 101888 gen.exitState = zd.gen_exitState[q];
1844 101888 gen.reloadState = zd.gen_reloadState[q];
1845 101888 gen.eventstate = zd.gen_eventstate[q];
1846 101888 gen.initd = zd.gen_initd[q];
1847 101888 gen.data = zd.gen_data[q];
1848 101888 }
1849 199 }
1850
1851 1 void save_genscript(gamedata& gd)
1852 {
1853
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 1 times.
513 for(size_t q = 0; q < NUMSCRIPTSGENERIC; ++q)
1854 {
1855 512 user_genscript const& gen = user_genscript::get(q);
1856 512 gd.gen_doscript.set(q, gen.doscript());
1857 512 gd.gen_exitState[q] = gen.exitState;
1858 512 gd.gen_reloadState[q] = gen.reloadState;
1859 512 gd.gen_eventstate[q] = gen.eventstate;
1860 512 gd.gen_initd[q] = gen.initd;
1861 512 gd.gen_data[q] = gen.data;
1862 512 }
1863 1 }
1864
1865 596824574 void FFScript::runGenericPassiveEngine(int32_t scrtm)
1866 {
1867
2/2
✓ Branch 0 taken 19575889 times.
✓ Branch 1 taken 577248685 times.
596824574 if(!max_valid_genscript) return; //No generic scripts in the quest!
1868 19575889 bool init = (scrtm == SCR_TIMING_INIT);
1869
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 19575788 times.
19575889 if(!init)
1870 {
1871
2/2
✓ Branch 0 taken 297552 times.
✓ Branch 1 taken 19278236 times.
19575788 if(genscript_timing != scrtm)
1872 {
1873
2/2
✓ Branch 0 taken 1661258 times.
✓ Branch 1 taken 297552 times.
1958810 while(genscript_timing != scrtm)
1874 1661258 runGenericPassiveEngine(genscript_timing);
1875 297552 }
1876 19575788 }
1877
2/2
✓ Branch 0 taken 255569051 times.
✓ Branch 1 taken 19575889 times.
275144940 for(auto q = 1; q <= max_valid_genscript; ++q)
1878 {
1879 255569051 user_genscript& scr = user_genscript::get(q);
1880
2/2
✓ Branch 0 taken 131909606 times.
✓ Branch 1 taken 123659445 times.
255569051 if(!scr.doscript()) continue;
1881
2/2
✓ Branch 0 taken 3460755 times.
✓ Branch 1 taken 128448851 times.
131909606 if(!genericscripts[q]->valid()) continue;
1882
2/2
✓ Branch 0 taken 75940592 times.
✓ Branch 1 taken 52508259 times.
128448851 if(scr.waitevent) continue;
1883
8/8
✓ Branch 0 taken 52508199 times.
✓ Branch 1 taken 60 times.
✓ Branch 2 taken 42159655 times.
✓ Branch 3 taken 10348544 times.
✓ Branch 4 taken 42159156 times.
✓ Branch 5 taken 499 times.
✓ Branch 6 taken 40022009 times.
✓ Branch 7 taken 2137147 times.
52508259 if(!init && (scr.waituntil > scrtm || (!scr.wait_atleast && scr.waituntil != scrtm)))
1884 50370553 continue;
1885
1886 //Run the script!
1887 2137706 ZScriptVersion::RunScript(ScriptType::Generic, q, q);
1888 2137706 }
1889
4/4
✓ Branch 0 taken 19575788 times.
✓ Branch 1 taken 101 times.
✓ Branch 2 taken 19074136 times.
✓ Branch 3 taken 501652 times.
19575889 if(init || genscript_timing >= SCR_TIMING_END_FRAME)
1890 501753 genscript_timing = SCR_TIMING_START_FRAME;
1891 19074136 else ++genscript_timing;
1892 596824574 }
1893
1894 13565 void FFScript::initZScriptDMapScripts()
1895 {
1896
2/4
✓ Branch 0 taken 13565 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13565 times.
✗ Branch 3 not taken.
13565 scriptEngineDatas[{ScriptType::DMap, 0}] = ScriptEngineData();
1897
2/4
✓ Branch 0 taken 13565 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13565 times.
✗ Branch 3 not taken.
13565 scriptEngineDatas[{ScriptType::ScriptedPassiveSubscreen, 0}] = ScriptEngineData();
1898 13565 }
1899
1900 1362 void FFScript::initZScriptSubscreenScript()
1901 {
1902
2/4
✓ Branch 0 taken 1362 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1362 times.
✗ Branch 3 not taken.
1362 scriptEngineDatas[{ScriptType::EngineSubscreen, 0}] = ScriptEngineData();
1903 1362 }
1904 13502 void FFScript::initZScriptScriptedActiveSubscreen()
1905 {
1906
2/4
✓ Branch 0 taken 13502 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13502 times.
✗ Branch 3 not taken.
13502 scriptEngineDatas[{ScriptType::ScriptedActiveSubscreen, 0}] = ScriptEngineData();
1907 13502 }
1908
1909 3 void FFScript::initZScriptOnMapScript()
1910 {
1911
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 scriptEngineDatas[{ScriptType::OnMap, 0}] = ScriptEngineData();
1912 3 }
1913
1914 2715 void FFScript::initZScriptHeroScripts()
1915 {
1916
2/4
✓ Branch 0 taken 2715 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2715 times.
✗ Branch 3 not taken.
2715 scriptEngineDatas[{ScriptType::Hero, 0}] = ScriptEngineData();
1917 2715 }
1918
1919 2427 void FFScript::initZScriptItemScripts()
1920 {
1921
2/2
✓ Branch 0 taken 621312 times.
✓ Branch 1 taken 2427 times.
623739 for ( int32_t q = 0; q < 256; q++ )
1922 {
1923 621312 auto& data = get_script_engine_data(ScriptType::Item, q);
1924 621312 data.reset();
1925
2/2
✓ Branch 0 taken 621310 times.
✓ Branch 1 taken 2 times.
621312 data.doscript = (itemsbuf[q].flags&item_passive_script) && game->item[q];
1926 621312 }
1927
1928
2/2
✓ Branch 0 taken 621312 times.
✓ Branch 1 taken 2427 times.
623739 for ( int32_t q = -256; q < 0; q++ )
1929 {
1930 621312 auto& data = get_script_engine_data(ScriptType::Item, q);
1931 621312 data.reset();
1932 621312 data.doscript = 0;
1933 621312 }
1934 2427 }
1935
1936 2658892 static int get_mouse_state(int index)
1937 {
1938 2658892 int value = 0;
1939
1/2
✓ Branch 0 taken 2658892 times.
✗ Branch 1 not taken.
2658892 if (replay_is_replaying())
1940 {
1941 2658892 value = replay_get_mouse(index);
1942 2658892 }
1943 else if (index == 0)
1944 {
1945 value = script_mouse_x;
1946 }
1947 else if (index == 1)
1948 {
1949 value = script_mouse_y;
1950 }
1951 else if (index == 2)
1952 {
1953 value = script_mouse_z;
1954 }
1955 else if (index == 3)
1956 {
1957 value = script_mouse_b;
1958 }
1959
1960
2/2
✓ Branch 0 taken 2657296 times.
✓ Branch 1 taken 1596 times.
2658892 if (replay_is_recording())
1961 {
1962 1596 replay_set_mouse(index, value);
1963 1596 }
1964
1965 2658892 return value;
1966 }
1967
1968 ///---------------------------------------------//
1969 // Array Helper Functions //
1970 ///---------------------------------------------//
1971
1972 #define ZCARRAY_MAX_SIZE 214748
1973
1974 303068722 size_t ArrayH::getSize(const int32_t ptr)
1975 {
1976 303068722 ArrayManager am(ptr);
1977 303068722 return am.size();
1978 }
1979
1980 //Can't you get the std::string and then check its length?
1981 int32_t ArrayH::strlen(const int32_t ptr)
1982 {
1983 ArrayManager am(ptr);
1984 if (am.invalid() || am.size() == 0)
1985 return -1;
1986
1987 word count;
1988 size_t sz = am.size();
1989 for(count = 0; BC::checkUserArrayIndex(count, sz) == _NoError
1990 && am.get(count) != '\0'; count++);
1991
1992 return count;
1993 }
1994
1995 //Returns values of a zscript array as an std::string.
1996 12210021 void ArrayH::getString(const int32_t ptr, string &str, dword num_chars, dword offset)
1997 {
1998 12210021 ArrayManager am(ptr);
1999
2000
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 12210016 times.
12210021 if(am.invalid())
2001 {
2002 5 str.clear();
2003 5 return;
2004 }
2005
2006 12210016 str.clear();
2007 12210016 size_t sz = am.size();
2008
5/6
✓ Branch 0 taken 173073041 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12210016 times.
✓ Branch 3 taken 160863025 times.
✓ Branch 4 taken 12210016 times.
✓ Branch 5 taken 160863025 times.
173073041 for(word i = offset; BC::checkUserArrayIndex(i, sz) == _NoError && am.get(i) != '\0' && num_chars != 0; i++)
2009 {
2010 160863025 int32_t c = am.get(i) / 10000;
2011
1/2
✓ Branch 0 taken 160863025 times.
✗ Branch 1 not taken.
160863025 if(byte(c) != c)
2012 {
2013 Z_scripterrlog("Illegal char value (%d) at position [%d] in string pointer %d\n", c, i, ptr);
2014 Z_scripterrlog("Value of invalid char will overflow.\n");
2015 }
2016 160863025 str += byte(c);
2017 160863025 --num_chars;
2018 160863025 }
2019 12210021 }
2020
2021 //Used for issues where reading the ZScript array floods the console with errors 'Accessing array index [12] size of 12.
2022 //Happens with Quad3D and some other functions, and I have no clue why. -Z ( 28th April, 2019 )
2023 //Like getString but for an array of longs instead of chars. *(arrayPtr is not checked for validity)
2024 void ArrayH::getValues2(const int32_t ptr, int32_t* arrayPtr, dword num_values, dword offset) //a hack -Z
2025 {
2026 ArrayManager am(ptr);
2027
2028 if(am.invalid())
2029 return;
2030
2031 size_t sz = am.size();
2032 for(word i = offset; BC::checkUserArrayIndex(i, sz+1) == _NoError && num_values != 0; i++)
2033 {
2034 arrayPtr[i] = (am.get(i) / 10000);
2035 num_values--;
2036 }
2037 }
2038
2039 //Like getString but for an array of longs instead of chars. *(arrayPtr is not checked for validity)
2040 1080 void ArrayH::getValues(const int32_t ptr, int32_t* arrayPtr, dword num_values, dword offset)
2041 {
2042 1080 ArrayManager am(ptr);
2043
2044
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1080 times.
1080 if (am.invalid())
2045 return;
2046 1080 size_t sz = am.size();
2047
4/4
✓ Branch 0 taken 1080 times.
✓ Branch 1 taken 12960 times.
✓ Branch 2 taken 1080 times.
✓ Branch 3 taken 12960 times.
14040 for(word i = offset; num_values != 0 && BC::checkUserArrayIndex(i, sz) == _NoError; i++)
2048 {
2049 12960 arrayPtr[i] = (am.get(i) / 10000);
2050 12960 num_values--;
2051 12960 }
2052 1080 }
2053
2054 1 void ArrayH::copyValues(const int32_t ptr, const int32_t ptr2)
2055 {
2056 1 ArrayManager am1(ptr), am2(ptr2);
2057
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if(am1.invalid() || am2.invalid())
2058 return;
2059
2060 1 int sz = std::min(am1.size(),am2.size());
2061
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 for (int i = 0; i < sz; i++)
2062 {
2063 2 am1.set(i,am2.get(i));
2064 2 }
2065 1 }
2066 //Get element from array
2067 1358556954 INLINE int32_t ArrayH::getElement(const int32_t ptr, int32_t offset, const bool neg)
2068 {
2069 1358556954 ArrayManager am(ptr,neg);
2070 1358556954 return am.get(offset);
2071 }
2072
2073 //Set element in array
2074 665958939 INLINE void ArrayH::setElement(const int32_t ptr, int32_t offset, const int32_t value, const bool neg)
2075 {
2076 665958939 ArrayManager am(ptr,neg);
2077 665958939 am.set(offset,value);
2078 665958939 }
2079
2080 3239157 int32_t ArrayH::setArray(const int32_t ptr, string const& s2, bool resize)
2081 {
2082 3239157 ArrayManager am(ptr);
2083
2084
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3239157 times.
3239157 if (am.invalid())
2085 return _InvalidPointer;
2086
2087 size_t i;
2088
2089
3/4
✓ Branch 0 taken 3239157 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3226365 times.
✓ Branch 3 taken 12792 times.
3239157 if(am.can_resize() && resize)
2090 12792 am.resize_min(s2.size()+1);
2091
2092 3239157 size_t sz = am.size();
2093
2/2
✓ Branch 0 taken 43401631 times.
✓ Branch 1 taken 3239088 times.
46640719 for(i = 0; i < s2.size(); i++)
2094 {
2095
2/2
✓ Branch 0 taken 43401562 times.
✓ Branch 1 taken 69 times.
43401631 if(i >= sz)
2096 {
2097 69 am.set(sz-1,'\0');
2098 69 return _Overflow;
2099 }
2100
2101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43401562 times.
43401562 if(BC::checkUserArrayIndex(i, sz) == _NoError)
2102 43401562 am.set(i,s2[i] * 10000);
2103 43401562 }
2104
2105
1/2
✓ Branch 0 taken 3239088 times.
✗ Branch 1 not taken.
3239088 if(BC::checkUserArrayIndex(i, sz) == _NoError)
2106 3239088 am.set(i,'\0');
2107
2108 3239088 return _NoError;
2109 3239157 }
2110
2111 2343661981 ArrayManager::ArrayManager(int32_t ptr, bool neg) : negAccess(neg), ptr(ptr)
2112 {
2113 2343661981 _invalid = false;
2114
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2343661981 times.
2343661981 if(ptr >= INTARR_OFFS)
2115 {
2116 aptr = nullptr;
2117 if(sz_int_arr(ptr) < 0)
2118 _invalid = true;
2119 }
2120
2/2
✓ Branch 0 taken 2343661262 times.
✓ Branch 1 taken 719 times.
2343661981 else if(ptr == 0)
2121 {
2122 719 aptr = &INVALIDARRAY;
2123 719 _invalid = true;
2124 719 }
2125
2/2
✓ Branch 0 taken 2343661140 times.
✓ Branch 1 taken 122 times.
2343661262 else if(ptr < 0) //An object array?
2126 {
2127 122 int32_t objptr = -ptr;
2128 122 auto it = objectRAM.find(objptr);
2129
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 122 times.
122 if(it == objectRAM.end())
2130 {
2131 aptr = &INVALIDARRAY;
2132 _invalid = true;
2133 }
2134 122 else aptr = &(it->second);
2135 122 }
2136
2/2
✓ Branch 0 taken 1847295671 times.
✓ Branch 1 taken 496365469 times.
2343661140 else if(ptr >= NUM_ZSCRIPT_ARRAYS) //Then it's a global
2137 {
2138 1847295671 dword gptr = ptr - NUM_ZSCRIPT_ARRAYS;
2139
2140
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1847295671 times.
1847295671 if(gptr > game->globalRAM.size())
2141 {
2142 aptr = &INVALIDARRAY;
2143 _invalid = true;
2144 }
2145 1847295671 else aptr = &(game->globalRAM[gptr]);
2146 1847295671 }
2147 else
2148 {
2149
1/2
✓ Branch 0 taken 496365469 times.
✗ Branch 1 not taken.
496365469 if(!localRAM[ptr].Valid())
2150 {
2151 aptr = &INVALIDARRAY;
2152 _invalid = true;
2153 }
2154 496365469 else aptr = &(localRAM[ptr]);
2155 }
2156
2/2
✓ Branch 0 taken 2343661262 times.
✓ Branch 1 taken 719 times.
2343661981 if(_invalid)
2157 {
2158 719 Z_scripterrlog("Invalid pointer (%i) passed to array "
2159 719 "(don't change the values of your array pointers)\n", ptr);
2160 719 }
2161 2343661981 }
2162 319146088 ArrayManager::ArrayManager(int32_t ptr) : ArrayManager(ptr,can_neg_array){}
2163
2164 1692506784 int32_t ArrayManager::get(int32_t indx) const
2165 {
2166
2/2
✓ Branch 0 taken 241 times.
✓ Branch 1 taken 1692506543 times.
1692506784 if(_invalid) return -10000;
2167 1692506543 int32_t sz = size();
2168
1/2
✓ Branch 0 taken 1692506543 times.
✗ Branch 1 not taken.
1692506543 if(aptr)
2169 {
2170
2/2
✓ Branch 0 taken 1691873057 times.
✓ Branch 1 taken 633486 times.
1692506543 if(BC::checkUserArrayIndex(indx, sz, negAccess) == SH::_NoError)
2171 {
2172
2/2
✓ Branch 0 taken 1691872861 times.
✓ Branch 1 taken 196 times.
1691873057 if(indx < 0)
2173 196 indx += sz; //[-1] becomes [size-1] -Em
2174 1691873057 return (*aptr)[indx];
2175 }
2176 633486 }
2177 else //internal special array
2178 {
2179 if(sz >= 0 && BC::checkUserArrayIndex(indx, sz, negAccess) == SH::_NoError)
2180 {
2181 if(indx < 0)
2182 indx += sz; //[-1] becomes [size-1] -Em
2183 return get_int_arr(ptr, indx);
2184 }
2185 }
2186 633486 return -10000;
2187 1692506784 }
2188 715447321 void ArrayManager::set(int32_t indx, int32_t val)
2189 {
2190
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 715447321 times.
715447321 if(_invalid) return;
2191 715447321 int32_t sz = size();
2192
1/2
✓ Branch 0 taken 715447321 times.
✗ Branch 1 not taken.
715447321 if(aptr)
2193 {
2194
2/2
✓ Branch 0 taken 715440023 times.
✓ Branch 1 taken 7298 times.
715447321 if(BC::checkUserArrayIndex(indx, sz, negAccess) == SH::_NoError)
2195 {
2196
1/2
✓ Branch 0 taken 715440023 times.
✗ Branch 1 not taken.
715440023 if(indx < 0)
2197 indx += sz; //[-1] becomes [size-1] -Em
2198
2/2
✓ Branch 0 taken 715439811 times.
✓ Branch 1 taken 212 times.
715440023 if (aptr->HoldsObjects())
2199 {
2200 212 int id = (*aptr)[indx];
2201 212 script_object_ref_dec(id);
2202 212 }
2203 715440023 (*aptr)[indx] = val;
2204
2/2
✓ Branch 0 taken 715439811 times.
✓ Branch 1 taken 212 times.
715440023 if (aptr->HoldsObjects())
2205 212 script_object_ref_inc(val);
2206 715440023 }
2207 715447321 }
2208 else //internal special array
2209 {
2210 if(sz >= 0 && BC::checkUserArrayIndex(indx, sz, negAccess) == SH::_NoError)
2211 {
2212 if(indx < 0)
2213 indx += sz; //[-1] becomes [size-1] -Em
2214 set_int_arr(ptr, indx, val);
2215 }
2216 }
2217 715447321 }
2218 2727045832 int32_t ArrayManager::size() const
2219 {
2220
2/2
✓ Branch 0 taken 473 times.
✓ Branch 1 taken 2727045359 times.
2727045832 if(_invalid) return -1;
2221
1/2
✓ Branch 0 taken 2727045359 times.
✗ Branch 1 not taken.
2727045359 if(aptr)
2222 2727045359 return aptr->Size();
2223 else // Internal special
2224 {
2225 int32_t sz = sz_int_arr(ptr);
2226 if(sz < 0)
2227 return -1;
2228 return sz;
2229 }
2230 2727045832 }
2231
2232 1150 bool ArrayManager::resize(size_t newsize)
2233 {
2234
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1150 times.
1150 if(_invalid) return false;
2235
1/2
✓ Branch 0 taken 1150 times.
✗ Branch 1 not taken.
1150 if(!aptr)
2236 {
2237 Z_scripterrlog("Special internal array '%d' not valid for operation 'Resize'\n", ptr);
2238 return false;
2239 }
2240
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1148 times.
1150 if (aptr->HoldsObjects())
2241 {
2242
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 for (int i = newsize; i < aptr->Size(); i++)
2243 {
2244 2 auto id = (*aptr)[i];
2245 2 script_object_ref_dec(id);
2246 2 }
2247 2 }
2248 1150 aptr->Resize(newsize);
2249 1150 return true;
2250 1150 }
2251 12792 bool ArrayManager::resize_min(size_t newsize)
2252 {
2253
2/2
✓ Branch 0 taken 12500 times.
✓ Branch 1 taken 292 times.
12792 if(size() >= newsize)
2254 12500 return true;
2255 292 return resize(newsize);
2256 12792 }
2257 3799264 bool ArrayManager::can_resize()
2258 {
2259
2/4
✓ Branch 0 taken 3799264 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3799264 times.
✗ Branch 3 not taken.
3799264 if(_invalid || !aptr)
2260 return false;
2261 3799264 return true;
2262 3799264 }
2263
2264 2 bool ArrayManager::push(int32_t val, int indx)
2265 {
2266
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(_invalid) return false;
2267
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!aptr)
2268 {
2269 scripting_log_error_with_context("Special internal array '{}' not valid for operation 'Push'", ptr);
2270 return false;
2271 }
2272
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(aptr->Size() == ZCARRAY_MAX_SIZE)
2273 return false;
2274 2 aptr->Push(val,indx);
2275
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (aptr->HoldsObjects())
2276 2 script_object_ref_inc(val);
2277 2 return true;
2278 2 }
2279 2 int32_t ArrayManager::pop(int indx)
2280 {
2281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(_invalid) return -10000;
2282
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!aptr)
2283 {
2284 Z_scripterrlog("Special internal array '%d' not valid for operation 'Push'\n", ptr);
2285 return -10000;
2286 }
2287
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(aptr->Empty())
2288 {
2289 Z_scripterrlog("Array %d had nothing to Pop!\n",ptr);
2290 return -10000;
2291 }
2292 2 int32_t val = aptr->Pop(indx);
2293
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (aptr->HoldsObjects())
2294 2 script_object_ref_dec(val);
2295 2 return val;
2296 2 }
2297
2298 std::string ArrayManager::asString(std::function<char const*(int32_t)> formatter, const size_t& limit) const
2299 {
2300 if(_invalid) return "{ INVALID ARRAY }";
2301 std::ostringstream oss;
2302 oss << "{ ";
2303 size_t s = size();
2304 bool overflow = limit < s;
2305 if(overflow)
2306 s = limit;
2307
2308 for(auto q = 0; q < s; ++q)
2309 {
2310 oss << formatter(get(q));
2311 if (q + 1 < s)
2312 oss << ", ";
2313 }
2314 if (overflow)
2315 oss << ", ...";
2316 oss << " }";
2317 return oss.str();
2318 }
2319
2320 2471587 void FFScript::deallocateAllScriptOwned(ScriptType scriptType, const int32_t UID)
2321 {
2322 2471587 std::vector<uint32_t> ids_to_clear;
2323
8/14
✓ Branch 0 taken 2471587 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2471587 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2471587 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 51746236 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 49274649 times.
✓ Branch 9 taken 2471587 times.
✓ Branch 10 taken 49274649 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 49274649 times.
✗ Branch 13 not taken.
51746236 for (auto& script_object : script_objects | std::views::values)
2324 {
2325
3/4
✓ Branch 0 taken 49274649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 149 times.
✓ Branch 3 taken 49274500 times.
49274649 if (script_object->own_clear(scriptType, UID))
2326 {
2327
1/2
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
149 ids_to_clear.push_back(script_object->id);
2328 149 script_object->owned_type = ScriptType::None;
2329 149 script_object->owned_i = 0;
2330 149 }
2331 }
2332
2333
6/8
✓ Branch 0 taken 2471587 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 975663 times.
✓ Branch 3 taken 1495924 times.
✓ Branch 4 taken 975663 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 587168 times.
✓ Branch 7 taken 388495 times.
2471587 if (ZScriptVersion::gc() && script_engine_data_exists(scriptType, UID))
2334 {
2335
1/2
✓ Branch 0 taken 587168 times.
✗ Branch 1 not taken.
587168 auto& data = get_script_engine_data(scriptType, UID);
2336
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 587168 times.
587168 for (uint32_t offset : data.ref.stack_pos_is_object)
2337 {
2338 uint32_t id = data.stack[offset];
2339 ids_to_clear.push_back(id);
2340 }
2341 587168 data.ref.stack_pos_is_object.clear();
2342 587168 }
2343
2344
3/4
✓ Branch 0 taken 2471587 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 975663 times.
✓ Branch 3 taken 1495924 times.
2471587 if (ZScriptVersion::gc())
2345 {
2346
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 975663 times.
975663 for (auto id : ids_to_clear)
2347 script_object_ref_dec(id);
2348 975663 }
2349 else
2350 {
2351
2/2
✓ Branch 0 taken 149 times.
✓ Branch 1 taken 1495924 times.
1496073 for (auto id : ids_to_clear)
2352
1/2
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
149 delete_script_object(id);
2353 }
2354
2355
2/2
✓ Branch 0 taken 10121148765 times.
✓ Branch 1 taken 2471587 times.
10123620352 for(int32_t i = 1; i < NUM_ZSCRIPT_ARRAYS; i++)
2356 {
2357
3/4
✓ Branch 0 taken 10121148765 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30730 times.
✓ Branch 3 taken 10121118035 times.
10121148765 if(arrayOwner[i].own_clear(scriptType,UID))
2358
1/2
✓ Branch 0 taken 30730 times.
✗ Branch 1 not taken.
30730 deallocateArray(i);
2359 10121148765 }
2360 2471587 }
2361
2362 71016 void FFScript::deallocateAllScriptOwnedOfType(ScriptType scriptType)
2363 {
2364 71016 std::vector<uint32_t> ids_to_clear;
2365
8/14
✓ Branch 0 taken 71016 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 71016 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 71016 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 252412 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 181396 times.
✓ Branch 9 taken 71016 times.
✓ Branch 10 taken 181396 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 181396 times.
✗ Branch 13 not taken.
252412 for (auto& script_object : script_objects | std::views::values)
2366 {
2367
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 181396 times.
181396 if (script_object->owned_type == scriptType)
2368 {
2369 ids_to_clear.push_back(script_object->id);
2370 script_object->owned_type = ScriptType::None;
2371 script_object->owned_i = 0;
2372 }
2373 }
2374
2375
3/4
✓ Branch 0 taken 71016 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36588 times.
✓ Branch 3 taken 34428 times.
71016 if (ZScriptVersion::gc())
2376 {
2377
2/2
✓ Branch 0 taken 18766162 times.
✓ Branch 1 taken 34428 times.
18800590 for (auto& [key, data] : scriptEngineDatas)
2378 {
2379
1/2
✓ Branch 0 taken 18766162 times.
✗ Branch 1 not taken.
18766162 if (key.first != scriptType)
2380 18766162 continue;
2381
2382 for (uint32_t offset : data.ref.stack_pos_is_object)
2383 {
2384 uint32_t id = data.stack[offset];
2385 ids_to_clear.push_back(id);
2386 }
2387 data.ref.stack_pos_is_object.clear();
2388 }
2389 34428 }
2390
2391
3/4
✓ Branch 0 taken 71016 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34428 times.
✓ Branch 3 taken 36588 times.
71016 if (ZScriptVersion::gc())
2392 {
2393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34428 times.
34428 for (auto id : ids_to_clear)
2394 script_object_ref_dec(id);
2395 34428 }
2396 else
2397 {
2398
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36588 times.
36588 for (auto id : ids_to_clear)
2399 delete_script_object(id);
2400 }
2401
2402
2/2
✓ Branch 0 taken 290810520 times.
✓ Branch 1 taken 71016 times.
290881536 for(int32_t i = 1; i < NUM_ZSCRIPT_ARRAYS; i++)
2403 {
2404
1/2
✓ Branch 0 taken 290810520 times.
✗ Branch 1 not taken.
290810520 if(arrayOwner[i].owned_type == scriptType)
2405 deallocateArray(i);
2406 290810520 }
2407 71016 }
2408
2409 // Only called when resetting the engine. Don't keep anything.
2410 371 void FFScript::deallocateAllScriptOwned()
2411 {
2412 371 script_object_ids_by_type.clear();
2413 371 script_objects.clear();
2414 371 next_script_object_id_freelist.clear();
2415
2416
2/2
✓ Branch 0 taken 1519245 times.
✓ Branch 1 taken 371 times.
1519616 for(int32_t i = 1; i < NUM_ZSCRIPT_ARRAYS; i++)
2417 {
2418
2/2
✓ Branch 0 taken 1519030 times.
✓ Branch 1 taken 215 times.
1519245 if(localRAM[i].Valid())
2419 {
2420 // Unowned arrays are ALSO deallocated!
2421 215 arrayOwner[i].clear();
2422 215 localRAM[i].Clear();
2423 215 }
2424 1519245 }
2425 371 }
2426
2427 681 void FFScript::deallocateAllScriptOwnedCont()
2428 {
2429 681 std::vector<uint32_t> ids_to_clear;
2430
8/14
✓ Branch 0 taken 681 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 681 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 681 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3835 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3154 times.
✓ Branch 9 taken 681 times.
✓ Branch 10 taken 3154 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3154 times.
✗ Branch 13 not taken.
3835 for (auto& script_object : script_objects | std::views::values)
2431 {
2432
2/4
✓ Branch 0 taken 3154 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3154 times.
3154 if (script_object->own_clear_cont())
2433 {
2434 ids_to_clear.push_back(script_object->id);
2435 script_object->owned_type = ScriptType::None;
2436 script_object->owned_i = 0;
2437 }
2438 }
2439
2440
3/4
✓ Branch 0 taken 681 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 391 times.
✓ Branch 3 taken 290 times.
681 if (ZScriptVersion::gc())
2441 {
2442
2/2
✓ Branch 0 taken 160125 times.
✓ Branch 1 taken 290 times.
320540 for (auto& [key, data] : scriptEngineDatas)
2443 {
2444
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 160125 times.
160125 for (uint32_t offset : data.ref.stack_pos_is_object)
2445 {
2446 uint32_t id = data.stack[offset];
2447 ids_to_clear.push_back(id);
2448 }
2449 160125 data.ref.stack_pos_is_object.clear();
2450 }
2451 290 }
2452
2453
3/4
✓ Branch 0 taken 681 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 290 times.
✓ Branch 3 taken 391 times.
681 if (ZScriptVersion::gc())
2454 {
2455
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 290 times.
290 for (auto id : ids_to_clear)
2456 script_object_ref_dec(id);
2457 290 }
2458 else
2459 {
2460
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 391 times.
391 for (auto id : ids_to_clear)
2461 delete_script_object(id);
2462 }
2463
2464 //No QR check here- always deallocate on quest exit.
2465
2/2
✓ Branch 0 taken 2788695 times.
✓ Branch 1 taken 681 times.
2789376 for(int32_t i = 1; i < NUM_ZSCRIPT_ARRAYS; i++)
2466 {
2467
3/4
✓ Branch 0 taken 2788695 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3165 times.
✓ Branch 3 taken 2785530 times.
2788695 if(localRAM[i].Valid())
2468 {
2469
2/4
✓ Branch 0 taken 3165 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3165 times.
✗ Branch 3 not taken.
3165 if(arrayOwner[i].own_clear_cont())
2470
1/2
✓ Branch 0 taken 3165 times.
✗ Branch 1 not taken.
3165 deallocateArray(i);
2471 3165 }
2472 2788695 }
2473 681 }
2474
2475 12139908 weapon *checkLWpn(int32_t uid)
2476 {
2477 12139908 return ResolveSprite<weapon>(uid, "lweapon");
2478 }
2479
2480 46579182 weapon *checkEWpn(int32_t uid)
2481 {
2482 46579182 return ResolveSprite<weapon>(uid, "eweapon");
2483 }
2484
2485 566 user_file *checkFile(int32_t ref, bool req_file = false, bool skipError = false)
2486 {
2487 566 user_file* file = user_files.check(ref, skipError);
2488
5/6
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 560 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 560 times.
✗ Branch 5 not taken.
566 if (file && req_file && !file->file)
2489 {
2490 if (skipError) return NULL;
2491
2492 scripting_log_error_with_context("Script attempted to reference an invalid file!");
2493 Z_scripterrlog("File with UID = %ld does not have an open file connection!\n", ref);
2494 Z_scripterrlog("Use '->Open()' or '->Create()' to hook to a system file.\n");
2495 return NULL;
2496 }
2497 566 return file;
2498 566 }
2499
2500 8474335 user_genscript *checkGenericScr(int32_t ref)
2501 {
2502
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8474335 times.
8474335 if (BC::checkBounds(ref, 1, NUMSCRIPTSGENERIC-1) != SH::_NoError)
2503 return NULL;
2504
2505 8474335 return &user_genscript::get(ref);
2506 8474335 }
2507 extern portal mirror_portal;
2508 portal *checkPortal(int32_t ref, bool skiperr = false)
2509 {
2510 if(ref == -1)
2511 return &mirror_portal;
2512
2513 portal* p = (portal*)portals.getByUID(ref);
2514 if(!p)
2515 {
2516 if(!skiperr)
2517 scripting_log_error_with_context("Invalid portal pointer: {}", ref);
2518 return nullptr;
2519 }
2520 return p;
2521 }
2522
2523 savedportal *checkSavedPortal(int32_t ref, bool skiperr = false)
2524 {
2525 savedportal* sp = game->getSavedPortal(ref);
2526 if(!sp)
2527 {
2528 if(!skiperr)
2529 scripting_log_error_with_context("Invalid savedportal pointer: {}", ref);
2530 return nullptr;
2531 }
2532 return sp;
2533 }
2534 int32_t getPortalFromSaved(savedportal* p)
2535 {
2536 if(p == &(game->saved_mirror_portal))
2537 return -1;
2538 portal* prtl = nullptr;
2539 portals.forEach([&](sprite& spr)
2540 {
2541 portal* tmp = (portal*)&spr;
2542 if(p->getUID() == tmp->saved_data)
2543 {
2544 prtl = tmp;
2545 return true;
2546 }
2547 return false;
2548 });
2549 return prtl ? prtl->getUID() : 0;
2550 }
2551
2552 user_dir *checkDir(int32_t ref, bool skipError = false)
2553 {
2554 return user_dirs.check(ref, skipError);
2555 }
2556
2557 user_stack *checkStack(int32_t ref, bool skipError = false)
2558 {
2559 return user_stacks.check(ref, skipError);
2560 }
2561
2562 449481 user_rng *checkRNG(int32_t ref, bool skipError = false)
2563 {
2564 // A null RNG pointer is special-case, access engine rng.
2565
2/2
✓ Branch 0 taken 447958 times.
✓ Branch 1 taken 1523 times.
449481 if (ref == 0) return &nulrng;
2566 1523 return user_rngs.check(ref, skipError);
2567 449481 }
2568
2569 17949 user_paldata* checkPalData(int32_t ref, bool skipError = false)
2570 {
2571 17949 return user_paldatas.check(ref, skipError);
2572 }
2573
2574 bottletype *checkBottleData(int32_t ref, bool skipError = false)
2575 {
2576 if(ref > 0 && ref <= 64)
2577 {
2578 return &QMisc.bottle_types[ref-1];
2579 }
2580 if(skipError) return NULL;
2581
2582 scripting_log_error_with_context("Invalid {} using UID = {}", "BottleData", ref);
2583 return NULL;
2584 }
2585
2586 bottleshoptype *checkBottleShopData(int32_t ref, bool skipError = false)
2587 {
2588 if(ref > 0 && ref <= 256)
2589 {
2590 return &QMisc.bottle_shop_types[ref-1];
2591 }
2592 if(skipError) return NULL;
2593
2594 scripting_log_error_with_context("Invalid {} using UID = {}", "BottleData", ref);
2595 return NULL;
2596 }
2597
2598 53396645 user_bitmap *checkBitmap(int32_t ref, bool req_valid = false, bool skipError = false)
2599 {
2600
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53396645 times.
53396645 switch (ref - 10)
2601 {
2602 case rtSCREEN:
2603 case rtBMP0:
2604 case rtBMP1:
2605 case rtBMP2:
2606 case rtBMP3:
2607 case rtBMP4:
2608 case rtBMP5:
2609 case rtBMP6:
2610 zprint2("Internal error: 'checkBitmap()' recieved ref pointing to system bitmap!\n");
2611 zprint2("Please report this as a bug!\n");
2612
2613 if(skipError) return NULL;
2614
2615 scripting_log_error_with_context("Tried to reference a non-existent bitmap with UID = {}", ref);
2616 return NULL;
2617
2618 default:
2619 {
2620 53396645 user_bitmap* b = user_bitmaps.check(ref, skipError);
2621
4/6
✓ Branch 0 taken 53366459 times.
✓ Branch 1 taken 30186 times.
✓ Branch 2 taken 53366459 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 53366459 times.
✗ Branch 5 not taken.
53396645 if (req_valid && (!b || !b->u_bmp))
2622 {
2623 if (skipError) return NULL;
2624
2625 scripting_log_error_with_context("Tried to reference an invalid user bitmap with UID = {}.", ref);
2626 Z_scripterrlog("Did you forget to create the bitmap with `new bitmap()` or `->Create()`?.\n");
2627 return NULL;
2628 }
2629 53396645 return b;
2630 }
2631 }
2632 53396645 }
2633
2634 extern const std::string subscr_names[sstMAX];
2635 109743 ZCSubscreen *checkSubData(int32_t ref, int req_ty = -1)
2636 {
2637 219486 auto [ptr,ty] = load_subdata(ref);
2638
1/2
✓ Branch 0 taken 109743 times.
✗ Branch 1 not taken.
109743 if(ptr)
2639 {
2640
4/6
✓ Branch 0 taken 5097 times.
✓ Branch 1 taken 104646 times.
✓ Branch 2 taken 5097 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5097 times.
✗ Branch 5 not taken.
109743 if(req_ty < 0 || req_ty == ty)
2641 109743 return ptr;
2642 else
2643 {
2644 scripting_log_error_with_context("Wrong type of SubscreenData accessed! Expecting type '{}', but found '{}'",
2645 subscr_names[req_ty], subscr_names[ty]);
2646 }
2647 }
2648 else scripting_log_error_with_context("Script attempted to reference a nonexistent SubscreenData!");
2649
2650 scripting_log_error_with_context("You were trying to reference an invalid SubscreenData with UID = {}", ref);
2651 return NULL;
2652 109743 }
2653 53553 SubscrPage *checkSubPage(int32_t ref, int req_ty = -1)
2654 {
2655 107106 auto [ptr,ty] = load_subpage(ref);
2656
1/2
✓ Branch 0 taken 53553 times.
✗ Branch 1 not taken.
53553 if(ptr)
2657 {
2658
4/6
✓ Branch 0 taken 14870 times.
✓ Branch 1 taken 38683 times.
✓ Branch 2 taken 14870 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14870 times.
✗ Branch 5 not taken.
53553 if(req_ty < 0 || req_ty == ty)
2659 53553 return ptr;
2660 else
2661 {
2662 scripting_log_error_with_context("Wrong type of Subscreen accessed! Expecting type '{}', but found '{}'",
2663 subscr_names[req_ty], subscr_names[ty]);
2664 }
2665 }
2666 else scripting_log_error_with_context("Script attempted to reference a nonexistent SubscreenPage!");
2667
2668 scripting_log_error_with_context("You were trying to reference an invalid SubscreenPage with UID = {}", ref);
2669 return NULL;
2670 53553 }
2671 103742 SubscrWidget *checkSubWidg(int32_t ref, int req_widg_ty = -1, int req_sub_ty = -1)
2672 {
2673 207484 auto [ptr,ty] = load_subwidg(ref);
2674
1/2
✓ Branch 0 taken 103742 times.
✗ Branch 1 not taken.
103742 if(ptr)
2675 {
2676
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 103742 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
103742 if(req_sub_ty < 0 || req_sub_ty == ty)
2677 {
2678
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 103742 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
103742 if(req_widg_ty < 0 || req_widg_ty == ptr->getType())
2679 103742 return ptr;
2680 else
2681 {
2682 auto listdata = GUI::ZCListData::subscr_widgets();
2683 scripting_log_error_with_context("Wrong type of SubscreenWidget accessed! Expecting type '{}', but found '{}'",
2684 listdata.findText(req_widg_ty), listdata.findText(ptr->getType()));
2685 }
2686 }
2687 else
2688 {
2689 scripting_log_error_with_context("Wrong type of Subscreen accessed! Expecting subscreen type '{}', but found '{}'",
2690 subscr_names[req_sub_ty], subscr_names[ty]);
2691 }
2692 }
2693 else scripting_log_error_with_context("Script attempted to reference a nonexistent SubscreenWidget!");
2694
2695 scripting_log_error_with_context("You were trying to reference an invalid SubscreenWidget with UID = {}", ref);
2696 return NULL;
2697 103742 }
2698
2699 static void bad_subwidg_type(bool func, byte type)
2700 {
2701 auto tyname = type < widgMAX ? subwidg_internal_names[type].c_str() : "";
2702 scripting_log_error_with_context("Widget type {} '{}' does not have this {}!",
2703 type, tyname, func ? "function" : "value");
2704 }
2705
2706 // TODO: Remove this.
2707 sprite *s;
2708
2709 3 int32_t item_flag(item_flags flag)
2710 {
2711
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(unsigned(ri->idata) >= MAXITEMS)
2712 {
2713 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
2714 return 0;
2715 }
2716 3 return (itemsbuf[ri->idata].flags & flag) ? 10000 : 0;
2717 3 }
2718 void item_flag(item_flags flag, bool val)
2719 {
2720 if(unsigned(ri->idata) >= MAXITEMS)
2721 {
2722 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
2723 return;
2724 }
2725 SETFLAG(itemsbuf[ri->idata].flags, flag, val);
2726 }
2727
2728 bool scripting_use_8bit_colors;
2729 int scripting_max_color_val;
2730
2731 440756 static int scripting_read_pal_color(int c)
2732 {
2733
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 440756 times.
440756 return scripting_use_8bit_colors ? c : c / 4;
2734 }
2735
2736 139440 static int scripting_write_pal_color(int c)
2737 {
2738
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 139440 times.
139440 return scripting_use_8bit_colors ? c : _rgb_scale_6[c];
2739 }
2740
2741 7760 void apply_qr_rule(int qr_id)
2742 {
2743 7760 bool value = get_qr(qr_id);
2744
6/6
✓ Branch 0 taken 2283 times.
✓ Branch 1 taken 1094 times.
✓ Branch 2 taken 1094 times.
✓ Branch 3 taken 1094 times.
✓ Branch 4 taken 1094 times.
✓ Branch 5 taken 1101 times.
7760 switch (qr_id)
2745 {
2746 case qr_LTTPWALK:
2747 1094 Hero.setDiagMove(value?1:0);
2748 1094 break;
2749 case qr_LTTPCOLLISION:
2750 1094 Hero.setBigHitbox(value?1:0);
2751 1094 break;
2752 case qr_ZS_NO_NEG_ARRAY:
2753 1094 can_neg_array = !value;
2754 1094 break;
2755 case qr_SCRIPTS_6_BIT_COLOR:
2756 {
2757
1/2
✓ Branch 0 taken 1094 times.
✗ Branch 1 not taken.
1094 if (value)
2758 {
2759 1094 scripting_use_8bit_colors = false;
2760 1094 scripting_max_color_val = 63;
2761 1094 }
2762 else
2763 {
2764 scripting_use_8bit_colors = true;
2765 scripting_max_color_val = 255;
2766 }
2767 1094 break;
2768 }
2769 case qr_HIDE_BOTTOM_8_PIXELS:
2770 {
2771 1101 updateShowBottomPixels();
2772 1101 break;
2773 }
2774 }
2775 7760 }
2776
2777 1094 static void apply_qr_rules()
2778 {
2779 1094 apply_qr_rule(qr_HIDE_BOTTOM_8_PIXELS);
2780 1094 apply_qr_rule(qr_LTTPCOLLISION);
2781 1094 apply_qr_rule(qr_LTTPWALK);
2782 1094 apply_qr_rule(qr_SCRIPTS_6_BIT_COLOR);
2783 1094 apply_qr_rule(qr_ZS_NO_NEG_ARRAY);
2784 1094 }
2785
2786 //Forward decl
2787 int32_t do_msgheight(int32_t msg);
2788 int32_t do_msgwidth(int32_t msg);
2789 //
2790
2791 template <typename T, size_t N>
2792 15143 static int read_array(const T(&arr)[N], int index)
2793 {
2794
2/10
✗ Branch 0 not taken.
✓ Branch 1 taken 15139 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
15143 if (BC::checkIndex(index, 0, N - 1) != SH::_NoError)
2795 return -1;
2796
2797 15143 return arr[index];
2798 15143 }
2799
2800 template <typename T, size_t N>
2801 58 static bool write_array(T(&arr)[N], int index, T value)
2802 {
2803
2/10
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 54 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 4 times.
58 if (BC::checkIndex(index, 0, N - 1) != SH::_NoError)
2804 return false;
2805
2806 58 arr[index] = value;
2807 58 return true;
2808 58 }
2809
2810 int32_t earlyretval = -1;
2811 3968278347 int32_t get_register(int32_t arg)
2812 {
2813
3/4
✓ Branch 0 taken 3968278347 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2856428684 times.
✓ Branch 3 taken 1111849663 times.
3968278347 if (arg >= D(0) && arg <= D(7))
2814 1111849663 return ri->d[arg - D(0)];
2815
2816
4/4
✓ Branch 0 taken 2378931647 times.
✓ Branch 1 taken 477497037 times.
✓ Branch 2 taken 2368700479 times.
✓ Branch 3 taken 10231168 times.
2856428684 if (arg >= GD(0) && arg <= GD(MAX_SCRIPT_REGISTERS))
2817 10231168 return game->global_d[arg - GD(0)];
2818
2819 2846197516 int32_t ret = 0;
2820
2821 #define GET_SPRITEDATA_VAR_INT(member) \
2822 { \
2823 if(unsigned(ri->spritedataref) > (MAXWPNS-1) ) \
2824 { \
2825 ret = -10000; \
2826 scripting_log_error_with_context("Invalid Sprite ID: {}", ri->spritedataref*10000); \
2827 } \
2828 else \
2829 ret = (wpnsbuf[ri->spritedataref].member * 10000); \
2830 }
2831
2832 2846197516 current_zasm_register = arg;
2833
2834 // Do not ever use `return` in these cases!
2835
366/1255
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 180367 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 205013 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 154 times.
✓ Branch 20 taken 1125663332 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 281838972 times.
✓ Branch 23 taken 3175230 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✓ Branch 26 taken 623627 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 13052062 times.
✓ Branch 29 taken 531424988 times.
✓ Branch 30 taken 2312685 times.
✓ Branch 31 taken 10 times.
✓ Branch 32 taken 24185371 times.
✓ Branch 33 taken 23746251 times.
✓ Branch 34 taken 5823966 times.
✓ Branch 35 taken 163102 times.
✓ Branch 36 taken 375 times.
✓ Branch 37 taken 51 times.
✓ Branch 38 taken 51 times.
✓ Branch 39 taken 4291571 times.
✓ Branch 40 taken 204076 times.
✓ Branch 41 taken 199035 times.
✓ Branch 42 taken 5283857 times.
✓ Branch 43 taken 5194596 times.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✓ Branch 46 taken 18378384 times.
✓ Branch 47 taken 231939 times.
✓ Branch 48 taken 41781171 times.
✗ Branch 49 not taken.
✓ Branch 50 taken 42668369 times.
✓ Branch 51 taken 4020681 times.
✓ Branch 52 taken 719568 times.
✗ Branch 53 not taken.
✓ Branch 54 taken 9094315 times.
✓ Branch 55 taken 441276 times.
✓ Branch 56 taken 24132812 times.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✓ Branch 59 taken 2790135 times.
✓ Branch 60 taken 1061314 times.
✓ Branch 61 taken 944827 times.
✓ Branch 62 taken 78365820 times.
✗ Branch 63 not taken.
✓ Branch 64 taken 204 times.
✓ Branch 65 taken 23758768 times.
✗ Branch 66 not taken.
✓ Branch 67 taken 5424 times.
✗ Branch 68 not taken.
✓ Branch 69 taken 1249005 times.
✓ Branch 70 taken 573955 times.
✓ Branch 71 taken 652486 times.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✗ Branch 74 not taken.
✓ Branch 75 taken 959935 times.
✓ Branch 76 taken 1095514 times.
✗ Branch 77 not taken.
✓ Branch 78 taken 7337405 times.
✓ Branch 79 taken 3244 times.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✓ Branch 83 taken 656387 times.
✓ Branch 84 taken 571655 times.
✓ Branch 85 taken 113145 times.
✓ Branch 86 taken 115547 times.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✗ Branch 90 not taken.
✓ Branch 91 taken 489104 times.
✓ Branch 92 taken 489104 times.
✓ Branch 93 taken 288295 times.
✗ Branch 94 not taken.
✗ Branch 95 not taken.
✓ Branch 96 taken 4101 times.
✗ Branch 97 not taken.
✓ Branch 98 taken 57322 times.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✗ Branch 101 not taken.
✓ Branch 102 taken 440770 times.
✓ Branch 103 taken 2 times.
✗ Branch 104 not taken.
✗ Branch 105 not taken.
✓ Branch 106 taken 428588 times.
✓ Branch 107 taken 432590 times.
✓ Branch 108 taken 337110 times.
✓ Branch 109 taken 273630 times.
✗ Branch 110 not taken.
✗ Branch 111 not taken.
✓ Branch 112 taken 271788 times.
✗ Branch 113 not taken.
✗ Branch 114 not taken.
✓ Branch 115 taken 832354 times.
✓ Branch 116 taken 18 times.
✗ Branch 117 not taken.
✗ Branch 118 not taken.
✓ Branch 119 taken 4357 times.
✗ Branch 120 not taken.
✗ Branch 121 not taken.
✗ Branch 122 not taken.
✓ Branch 123 taken 1012 times.
✗ Branch 124 not taken.
✗ Branch 125 not taken.
✗ Branch 126 not taken.
✗ Branch 127 not taken.
✗ Branch 128 not taken.
✗ Branch 129 not taken.
✗ Branch 130 not taken.
✗ Branch 131 not taken.
✗ Branch 132 not taken.
✗ Branch 133 not taken.
✗ Branch 134 not taken.
✗ Branch 135 not taken.
✗ Branch 136 not taken.
✗ Branch 137 not taken.
✗ Branch 138 not taken.
✗ Branch 139 not taken.
✗ Branch 140 not taken.
✓ Branch 141 taken 136185 times.
✗ Branch 142 not taken.
✗ Branch 143 not taken.
✗ Branch 144 not taken.
✗ Branch 145 not taken.
✗ Branch 146 not taken.
✗ Branch 147 not taken.
✗ Branch 148 not taken.
✗ Branch 149 not taken.
✓ Branch 150 taken 92967 times.
✓ Branch 151 taken 4123 times.
✓ Branch 152 taken 4321356 times.
✓ Branch 153 taken 3824036 times.
✓ Branch 154 taken 4211785 times.
✓ Branch 155 taken 4388042 times.
✓ Branch 156 taken 6701954 times.
✓ Branch 157 taken 5699839 times.
✓ Branch 158 taken 3218568 times.
✓ Branch 159 taken 3214309 times.
✓ Branch 160 taken 120159 times.
✓ Branch 161 taken 120450 times.
✓ Branch 162 taken 23391 times.
✓ Branch 163 taken 23391 times.
✗ Branch 164 not taken.
✗ Branch 165 not taken.
✗ Branch 166 not taken.
✗ Branch 167 not taken.
✓ Branch 168 taken 791031 times.
✓ Branch 169 taken 791031 times.
✗ Branch 170 not taken.
✓ Branch 171 taken 1073638 times.
✓ Branch 172 taken 818518 times.
✓ Branch 173 taken 335732 times.
✓ Branch 174 taken 1118025 times.
✓ Branch 175 taken 1056398 times.
✓ Branch 176 taken 963357 times.
✓ Branch 177 taken 870340 times.
✓ Branch 178 taken 2442823 times.
✓ Branch 179 taken 1811399 times.
✓ Branch 180 taken 2061226 times.
✓ Branch 181 taken 1845780 times.
✓ Branch 182 taken 1237553 times.
✓ Branch 183 taken 1081361 times.
✓ Branch 184 taken 558264 times.
✓ Branch 185 taken 669416 times.
✗ Branch 186 not taken.
✗ Branch 187 not taken.
✗ Branch 188 not taken.
✗ Branch 189 not taken.
✓ Branch 190 taken 4870 times.
✓ Branch 191 taken 286348 times.
✓ Branch 192 taken 672937 times.
✓ Branch 193 taken 4686 times.
✗ Branch 194 not taken.
✓ Branch 195 taken 1121 times.
✓ Branch 196 taken 14018 times.
✗ Branch 197 not taken.
✗ Branch 198 not taken.
✗ Branch 199 not taken.
✗ Branch 200 not taken.
✗ Branch 201 not taken.
✗ Branch 202 not taken.
✓ Branch 203 taken 3192 times.
✗ Branch 204 not taken.
✗ Branch 205 not taken.
✗ Branch 206 not taken.
✗ Branch 207 not taken.
✗ Branch 208 not taken.
✗ Branch 209 not taken.
✗ Branch 210 not taken.
✗ Branch 211 not taken.
✗ Branch 212 not taken.
✗ Branch 213 not taken.
✗ Branch 214 not taken.
✗ Branch 215 not taken.
✗ Branch 216 not taken.
✗ Branch 217 not taken.
✗ Branch 218 not taken.
✗ Branch 219 not taken.
✗ Branch 220 not taken.
✗ Branch 221 not taken.
✗ Branch 222 not taken.
✗ Branch 223 not taken.
✗ Branch 224 not taken.
✗ Branch 225 not taken.
✗ Branch 226 not taken.
✗ Branch 227 not taken.
✗ Branch 228 not taken.
✗ Branch 229 not taken.
✗ Branch 230 not taken.
✗ Branch 231 not taken.
✓ Branch 232 taken 53 times.
✗ Branch 233 not taken.
✗ Branch 234 not taken.
✗ Branch 235 not taken.
✗ Branch 236 not taken.
✗ Branch 237 not taken.
✓ Branch 238 taken 5960535 times.
✓ Branch 239 taken 16858 times.
✓ Branch 240 taken 3 times.
✗ Branch 241 not taken.
✗ Branch 242 not taken.
✗ Branch 243 not taken.
✗ Branch 244 not taken.
✗ Branch 245 not taken.
✗ Branch 246 not taken.
✗ Branch 247 not taken.
✗ Branch 248 not taken.
✗ Branch 249 not taken.
✗ Branch 250 not taken.
✗ Branch 251 not taken.
✗ Branch 252 not taken.
✗ Branch 253 not taken.
✗ Branch 254 not taken.
✓ Branch 255 taken 1994 times.
✓ Branch 256 taken 1914 times.
✗ Branch 257 not taken.
✗ Branch 258 not taken.
✗ Branch 259 not taken.
✗ Branch 260 not taken.
✗ Branch 261 not taken.
✗ Branch 262 not taken.
✗ Branch 263 not taken.
✗ Branch 264 not taken.
✗ Branch 265 not taken.
✗ Branch 266 not taken.
✗ Branch 267 not taken.
✗ Branch 268 not taken.
✗ Branch 269 not taken.
✗ Branch 270 not taken.
✓ Branch 271 taken 55670 times.
✗ Branch 272 not taken.
✓ Branch 273 taken 55645 times.
✗ Branch 274 not taken.
✓ Branch 275 taken 63041 times.
✓ Branch 276 taken 142873 times.
✓ Branch 277 taken 74538 times.
✗ Branch 278 not taken.
✗ Branch 279 not taken.
✗ Branch 280 not taken.
✗ Branch 281 not taken.
✗ Branch 282 not taken.
✗ Branch 283 not taken.
✗ Branch 284 not taken.
✗ Branch 285 not taken.
✗ Branch 286 not taken.
✗ Branch 287 not taken.
✗ Branch 288 not taken.
✗ Branch 289 not taken.
✓ Branch 290 taken 954757 times.
✗ Branch 291 not taken.
✓ Branch 292 taken 950150 times.
✓ Branch 293 taken 109736 times.
✓ Branch 294 taken 6 times.
✗ Branch 295 not taken.
✓ Branch 296 taken 80933 times.
✗ Branch 297 not taken.
✓ Branch 298 taken 5388 times.
✓ Branch 299 taken 416 times.
✗ Branch 300 not taken.
✓ Branch 301 taken 246 times.
✗ Branch 302 not taken.
✓ Branch 303 taken 6 times.
✗ Branch 304 not taken.
✗ Branch 305 not taken.
✓ Branch 306 taken 6 times.
✓ Branch 307 taken 103896 times.
✓ Branch 308 taken 7611 times.
✓ Branch 309 taken 4109108 times.
✓ Branch 310 taken 53697 times.
✓ Branch 311 taken 586 times.
✗ Branch 312 not taken.
✓ Branch 313 taken 53381 times.
✓ Branch 314 taken 220 times.
✓ Branch 315 taken 4362 times.
✓ Branch 316 taken 6 times.
✓ Branch 317 taken 4362 times.
✓ Branch 318 taken 6 times.
✗ Branch 319 not taken.
✓ Branch 320 taken 1950927 times.
✓ Branch 321 taken 6 times.
✓ Branch 322 taken 835937 times.
✓ Branch 323 taken 23909 times.
✓ Branch 324 taken 299718 times.
✓ Branch 325 taken 296970 times.
✓ Branch 326 taken 10231 times.
✓ Branch 327 taken 11477 times.
✗ Branch 328 not taken.
✗ Branch 329 not taken.
✗ Branch 330 not taken.
✓ Branch 331 taken 6 times.
✓ Branch 332 taken 283042 times.
✓ Branch 333 taken 284996 times.
✓ Branch 334 taken 36540 times.
✓ Branch 335 taken 32019 times.
✓ Branch 336 taken 32019 times.
✓ Branch 337 taken 1668140 times.
✓ Branch 338 taken 5455 times.
✗ Branch 339 not taken.
✗ Branch 340 not taken.
✗ Branch 341 not taken.
✓ Branch 342 taken 3 times.
✓ Branch 343 taken 60075 times.
✗ Branch 344 not taken.
✓ Branch 345 taken 180 times.
✗ Branch 346 not taken.
✗ Branch 347 not taken.
✓ Branch 348 taken 1552 times.
✗ Branch 349 not taken.
✗ Branch 350 not taken.
✗ Branch 351 not taken.
✗ Branch 352 not taken.
✓ Branch 353 taken 1551 times.
✗ Branch 354 not taken.
✗ Branch 355 not taken.
✗ Branch 356 not taken.
✓ Branch 357 taken 48553 times.
✗ Branch 358 not taken.
✗ Branch 359 not taken.
✗ Branch 360 not taken.
✗ Branch 361 not taken.
✗ Branch 362 not taken.
✗ Branch 363 not taken.
✗ Branch 364 not taken.
✗ Branch 365 not taken.
✗ Branch 366 not taken.
✗ Branch 367 not taken.
✗ Branch 368 not taken.
✗ Branch 369 not taken.
✗ Branch 370 not taken.
✗ Branch 371 not taken.
✓ Branch 372 taken 4354386 times.
✗ Branch 373 not taken.
✓ Branch 374 taken 4354484 times.
✓ Branch 375 taken 552907 times.
✗ Branch 376 not taken.
✗ Branch 377 not taken.
✓ Branch 378 taken 61563 times.
✓ Branch 379 taken 2845 times.
✗ Branch 380 not taken.
✓ Branch 381 taken 610345 times.
✓ Branch 382 taken 718383 times.
✗ Branch 383 not taken.
✗ Branch 384 not taken.
✗ Branch 385 not taken.
✓ Branch 386 taken 136793 times.
✗ Branch 387 not taken.
✗ Branch 388 not taken.
✓ Branch 389 taken 46359 times.
✓ Branch 390 taken 90304 times.
✓ Branch 391 taken 6052 times.
✓ Branch 392 taken 2800078 times.
✗ Branch 393 not taken.
✓ Branch 394 taken 65315 times.
✗ Branch 395 not taken.
✓ Branch 396 taken 96 times.
✗ Branch 397 not taken.
✓ Branch 398 taken 96 times.
✗ Branch 399 not taken.
✓ Branch 400 taken 12006 times.
✓ Branch 401 taken 218 times.
✓ Branch 402 taken 6012051 times.
✓ Branch 403 taken 10477 times.
✗ Branch 404 not taken.
✓ Branch 405 taken 157773 times.
✓ Branch 406 taken 157773 times.
✓ Branch 407 taken 48464 times.
✓ Branch 408 taken 60558 times.
✗ Branch 409 not taken.
✗ Branch 410 not taken.
✗ Branch 411 not taken.
✓ Branch 412 taken 1880 times.
✓ Branch 413 taken 149564 times.
✓ Branch 414 taken 149564 times.
✓ Branch 415 taken 81355 times.
✓ Branch 416 taken 125257 times.
✓ Branch 417 taken 125257 times.
✓ Branch 418 taken 25064738 times.
✓ Branch 419 taken 10565 times.
✗ Branch 420 not taken.
✗ Branch 421 not taken.
✗ Branch 422 not taken.
✗ Branch 423 not taken.
✓ Branch 424 taken 43 times.
✓ Branch 425 taken 16680 times.
✗ Branch 426 not taken.
✗ Branch 427 not taken.
✗ Branch 428 not taken.
✗ Branch 429 not taken.
✗ Branch 430 not taken.
✗ Branch 431 not taken.
✗ Branch 432 not taken.
✗ Branch 433 not taken.
✗ Branch 434 not taken.
✓ Branch 435 taken 30735 times.
✗ Branch 436 not taken.
✗ Branch 437 not taken.
✗ Branch 438 not taken.
✗ Branch 439 not taken.
✗ Branch 440 not taken.
✗ Branch 441 not taken.
✗ Branch 442 not taken.
✗ Branch 443 not taken.
✗ Branch 444 not taken.
✗ Branch 445 not taken.
✗ Branch 446 not taken.
✗ Branch 447 not taken.
✗ Branch 448 not taken.
✗ Branch 449 not taken.
✗ Branch 450 not taken.
✓ Branch 451 taken 8380661 times.
✓ Branch 452 taken 1754 times.
✗ Branch 453 not taken.
✗ Branch 454 not taken.
✗ Branch 455 not taken.
✗ Branch 456 not taken.
✓ Branch 457 taken 792465 times.
✗ Branch 458 not taken.
✗ Branch 459 not taken.
✗ Branch 460 not taken.
✓ Branch 461 taken 20977804 times.
✓ Branch 462 taken 225 times.
✓ Branch 463 taken 63717 times.
✓ Branch 464 taken 11270839 times.
✓ Branch 465 taken 96 times.
✗ Branch 466 not taken.
✓ Branch 467 taken 58183880 times.
✓ Branch 468 taken 15080301 times.
✗ Branch 469 not taken.
✗ Branch 470 not taken.
✗ Branch 471 not taken.
✗ Branch 472 not taken.
✗ Branch 473 not taken.
✗ Branch 474 not taken.
✗ Branch 475 not taken.
✗ Branch 476 not taken.
✗ Branch 477 not taken.
✗ Branch 478 not taken.
✗ Branch 479 not taken.
✗ Branch 480 not taken.
✓ Branch 481 taken 45964257 times.
✓ Branch 482 taken 2740280 times.
✓ Branch 483 taken 13058666 times.
✓ Branch 484 taken 54645118 times.
✓ Branch 485 taken 7680829 times.
✓ Branch 486 taken 211493 times.
✗ Branch 487 not taken.
✓ Branch 488 taken 47264 times.
✓ Branch 489 taken 39568 times.
✓ Branch 490 taken 64 times.
✓ Branch 491 taken 20 times.
✓ Branch 492 taken 32 times.
✓ Branch 493 taken 982758 times.
✗ Branch 494 not taken.
✗ Branch 495 not taken.
✗ Branch 496 not taken.
✓ Branch 497 taken 24940 times.
✓ Branch 498 taken 21112 times.
✓ Branch 499 taken 8014 times.
✓ Branch 500 taken 11842 times.
✗ Branch 501 not taken.
✗ Branch 502 not taken.
✗ Branch 503 not taken.
✗ Branch 504 not taken.
✗ Branch 505 not taken.
✗ Branch 506 not taken.
✗ Branch 507 not taken.
✗ Branch 508 not taken.
✓ Branch 509 taken 7 times.
✓ Branch 510 taken 7 times.
✗ Branch 511 not taken.
✗ Branch 512 not taken.
✗ Branch 513 not taken.
✗ Branch 514 not taken.
✗ Branch 515 not taken.
✓ Branch 516 taken 1026 times.
✗ Branch 517 not taken.
✗ Branch 518 not taken.
✗ Branch 519 not taken.
✗ Branch 520 not taken.
✗ Branch 521 not taken.
✗ Branch 522 not taken.
✗ Branch 523 not taken.
✓ Branch 524 taken 1124 times.
✗ Branch 525 not taken.
✗ Branch 526 not taken.
✗ Branch 527 not taken.
✓ Branch 528 taken 10 times.
✓ Branch 529 taken 152 times.
✗ Branch 530 not taken.
✗ Branch 531 not taken.
✗ Branch 532 not taken.
✗ Branch 533 not taken.
✗ Branch 534 not taken.
✗ Branch 535 not taken.
✗ Branch 536 not taken.
✓ Branch 537 taken 54 times.
✗ Branch 538 not taken.
✗ Branch 539 not taken.
✗ Branch 540 not taken.
✗ Branch 541 not taken.
✗ Branch 542 not taken.
✗ Branch 543 not taken.
✗ Branch 544 not taken.
✓ Branch 545 taken 109824 times.
✗ Branch 546 not taken.
✗ Branch 547 not taken.
✗ Branch 548 not taken.
✗ Branch 549 not taken.
✗ Branch 550 not taken.
✗ Branch 551 not taken.
✗ Branch 552 not taken.
✗ Branch 553 not taken.
✗ Branch 554 not taken.
✗ Branch 555 not taken.
✗ Branch 556 not taken.
✗ Branch 557 not taken.
✗ Branch 558 not taken.
✓ Branch 559 taken 17 times.
✗ Branch 560 not taken.
✗ Branch 561 not taken.
✗ Branch 562 not taken.
✓ Branch 563 taken 2062 times.
✗ Branch 564 not taken.
✗ Branch 565 not taken.
✓ Branch 566 taken 47 times.
✓ Branch 567 taken 3 times.
✗ Branch 568 not taken.
✓ Branch 569 taken 910 times.
✗ Branch 570 not taken.
✗ Branch 571 not taken.
✓ Branch 572 taken 9492 times.
✓ Branch 573 taken 2574375 times.
✓ Branch 574 taken 43250 times.
✗ Branch 575 not taken.
✓ Branch 576 taken 6 times.
✓ Branch 577 taken 4 times.
✗ Branch 578 not taken.
✗ Branch 579 not taken.
✗ Branch 580 not taken.
✗ Branch 581 not taken.
✗ Branch 582 not taken.
✗ Branch 583 not taken.
✗ Branch 584 not taken.
✗ Branch 585 not taken.
✗ Branch 586 not taken.
✓ Branch 587 taken 10246 times.
✓ Branch 588 taken 7214 times.
✓ Branch 589 taken 2391 times.
✓ Branch 590 taken 11161012 times.
✓ Branch 591 taken 4473523 times.
✓ Branch 592 taken 704596 times.
✓ Branch 593 taken 25369203 times.
✓ Branch 594 taken 47 times.
✓ Branch 595 taken 2 times.
✓ Branch 596 taken 343159 times.
✓ Branch 597 taken 100950 times.
✗ Branch 598 not taken.
✗ Branch 599 not taken.
✗ Branch 600 not taken.
✓ Branch 601 taken 1636 times.
✓ Branch 602 taken 1610 times.
✓ Branch 603 taken 32 times.
✗ Branch 604 not taken.
✗ Branch 605 not taken.
✗ Branch 606 not taken.
✗ Branch 607 not taken.
✗ Branch 608 not taken.
✗ Branch 609 not taken.
✗ Branch 610 not taken.
✗ Branch 611 not taken.
✗ Branch 612 not taken.
✗ Branch 613 not taken.
✗ Branch 614 not taken.
✓ Branch 615 taken 16 times.
✗ Branch 616 not taken.
✓ Branch 617 taken 16 times.
✗ Branch 618 not taken.
✓ Branch 619 taken 16 times.
✓ Branch 620 taken 16 times.
✗ Branch 621 not taken.
✗ Branch 622 not taken.
✗ Branch 623 not taken.
✓ Branch 624 taken 6567187 times.
✓ Branch 625 taken 3856 times.
✓ Branch 626 taken 192 times.
✗ Branch 627 not taken.
✗ Branch 628 not taken.
✗ Branch 629 not taken.
✗ Branch 630 not taken.
✗ Branch 631 not taken.
✗ Branch 632 not taken.
✗ Branch 633 not taken.
✗ Branch 634 not taken.
✗ Branch 635 not taken.
✗ Branch 636 not taken.
✗ Branch 637 not taken.
✗ Branch 638 not taken.
✗ Branch 639 not taken.
✗ Branch 640 not taken.
✗ Branch 641 not taken.
✓ Branch 642 taken 192 times.
✗ Branch 643 not taken.
✗ Branch 644 not taken.
✗ Branch 645 not taken.
✗ Branch 646 not taken.
✗ Branch 647 not taken.
✗ Branch 648 not taken.
✗ Branch 649 not taken.
✗ Branch 650 not taken.
✗ Branch 651 not taken.
✗ Branch 652 not taken.
✗ Branch 653 not taken.
✗ Branch 654 not taken.
✗ Branch 655 not taken.
✗ Branch 656 not taken.
✗ Branch 657 not taken.
✗ Branch 658 not taken.
✗ Branch 659 not taken.
✗ Branch 660 not taken.
✗ Branch 661 not taken.
✗ Branch 662 not taken.
✓ Branch 663 taken 13 times.
✓ Branch 664 taken 13 times.
✗ Branch 665 not taken.
✗ Branch 666 not taken.
✗ Branch 667 not taken.
✗ Branch 668 not taken.
✓ Branch 669 taken 128 times.
✓ Branch 670 taken 128 times.
✓ Branch 671 taken 128 times.
✗ Branch 672 not taken.
✗ Branch 673 not taken.
✗ Branch 674 not taken.
✗ Branch 675 not taken.
✗ Branch 676 not taken.
✗ Branch 677 not taken.
✗ Branch 678 not taken.
✓ Branch 679 taken 200 times.
✓ Branch 680 taken 8 times.
✓ Branch 681 taken 5 times.
✓ Branch 682 taken 392 times.
✓ Branch 683 taken 392 times.
✓ Branch 684 taken 5 times.
✓ Branch 685 taken 5 times.
✓ Branch 686 taken 5 times.
✓ Branch 687 taken 5 times.
✓ Branch 688 taken 91 times.
✗ Branch 689 not taken.
✓ Branch 690 taken 32 times.
✗ Branch 691 not taken.
✗ Branch 692 not taken.
✗ Branch 693 not taken.
✗ Branch 694 not taken.
✓ Branch 695 taken 8 times.
✓ Branch 696 taken 8 times.
✓ Branch 697 taken 5 times.
✓ Branch 698 taken 5 times.
✗ Branch 699 not taken.
✓ Branch 700 taken 1556485 times.
✓ Branch 701 taken 2004 times.
✗ Branch 702 not taken.
✗ Branch 703 not taken.
✗ Branch 704 not taken.
✗ Branch 705 not taken.
✗ Branch 706 not taken.
✗ Branch 707 not taken.
✗ Branch 708 not taken.
✗ Branch 709 not taken.
✗ Branch 710 not taken.
✗ Branch 711 not taken.
✓ Branch 712 taken 18 times.
✓ Branch 713 taken 42 times.
✓ Branch 714 taken 6 times.
✗ Branch 715 not taken.
✓ Branch 716 taken 37440165 times.
✓ Branch 717 taken 37290663 times.
✓ Branch 718 taken 6005247 times.
✓ Branch 719 taken 5030699 times.
✓ Branch 720 taken 388122 times.
✓ Branch 721 taken 90005 times.
✗ Branch 722 not taken.
✓ Branch 723 taken 45056 times.
✗ Branch 724 not taken.
✗ Branch 725 not taken.
✗ Branch 726 not taken.
✗ Branch 727 not taken.
✗ Branch 728 not taken.
✗ Branch 729 not taken.
✗ Branch 730 not taken.
✗ Branch 731 not taken.
✗ Branch 732 not taken.
✗ Branch 733 not taken.
✗ Branch 734 not taken.
✗ Branch 735 not taken.
✗ Branch 736 not taken.
✗ Branch 737 not taken.
✗ Branch 738 not taken.
✓ Branch 739 taken 701 times.
✓ Branch 740 taken 225 times.
✗ Branch 741 not taken.
✓ Branch 742 taken 6 times.
✗ Branch 743 not taken.
✓ Branch 744 taken 212 times.
✓ Branch 745 taken 19 times.
✗ Branch 746 not taken.
✗ Branch 747 not taken.
✓ Branch 748 taken 1124 times.
✓ Branch 749 taken 1095768 times.
✓ Branch 750 taken 43092 times.
✓ Branch 751 taken 45 times.
✓ Branch 752 taken 1402 times.
✓ Branch 753 taken 17 times.
✗ Branch 754 not taken.
✗ Branch 755 not taken.
✗ Branch 756 not taken.
✗ Branch 757 not taken.
✓ Branch 758 taken 5120 times.
✗ Branch 759 not taken.
✗ Branch 760 not taken.
✓ Branch 761 taken 6 times.
✗ Branch 762 not taken.
✗ Branch 763 not taken.
✗ Branch 764 not taken.
✗ Branch 765 not taken.
✗ Branch 766 not taken.
✗ Branch 767 not taken.
✗ Branch 768 not taken.
✗ Branch 769 not taken.
✗ Branch 770 not taken.
✓ Branch 771 taken 22016 times.
✗ Branch 772 not taken.
✗ Branch 773 not taken.
✗ Branch 774 not taken.
✗ Branch 775 not taken.
✗ Branch 776 not taken.
✗ Branch 777 not taken.
✗ Branch 778 not taken.
✗ Branch 779 not taken.
✗ Branch 780 not taken.
✗ Branch 781 not taken.
✗ Branch 782 not taken.
✗ Branch 783 not taken.
✗ Branch 784 not taken.
✗ Branch 785 not taken.
✗ Branch 786 not taken.
✗ Branch 787 not taken.
✗ Branch 788 not taken.
✗ Branch 789 not taken.
✗ Branch 790 not taken.
✗ Branch 791 not taken.
✗ Branch 792 not taken.
✗ Branch 793 not taken.
✗ Branch 794 not taken.
✗ Branch 795 not taken.
✗ Branch 796 not taken.
✗ Branch 797 not taken.
✗ Branch 798 not taken.
✗ Branch 799 not taken.
✗ Branch 800 not taken.
✗ Branch 801 not taken.
✓ Branch 802 taken 60340 times.
✓ Branch 803 taken 12211 times.
✓ Branch 804 taken 208371 times.
✓ Branch 805 taken 19038 times.
✓ Branch 806 taken 116988 times.
✓ Branch 807 taken 112420 times.
✗ Branch 808 not taken.
✗ Branch 809 not taken.
✗ Branch 810 not taken.
✓ Branch 811 taken 4546 times.
✓ Branch 812 taken 6890 times.
✓ Branch 813 taken 755 times.
✓ Branch 814 taken 5110 times.
✗ Branch 815 not taken.
✗ Branch 816 not taken.
✗ Branch 817 not taken.
✓ Branch 818 taken 463074 times.
✗ Branch 819 not taken.
✗ Branch 820 not taken.
✗ Branch 821 not taken.
✗ Branch 822 not taken.
✗ Branch 823 not taken.
✗ Branch 824 not taken.
✗ Branch 825 not taken.
✗ Branch 826 not taken.
✗ Branch 827 not taken.
✓ Branch 828 taken 94 times.
✓ Branch 829 taken 7891 times.
✓ Branch 830 taken 17628 times.
✓ Branch 831 taken 136 times.
✓ Branch 832 taken 13556 times.
✗ Branch 833 not taken.
✓ Branch 834 taken 18 times.
✗ Branch 835 not taken.
✓ Branch 836 taken 3199 times.
✗ Branch 837 not taken.
✗ Branch 838 not taken.
✗ Branch 839 not taken.
✗ Branch 840 not taken.
✗ Branch 841 not taken.
✗ Branch 842 not taken.
✗ Branch 843 not taken.
✗ Branch 844 not taken.
✗ Branch 845 not taken.
✗ Branch 846 not taken.
✗ Branch 847 not taken.
✗ Branch 848 not taken.
✗ Branch 849 not taken.
✗ Branch 850 not taken.
✗ Branch 851 not taken.
✗ Branch 852 not taken.
✓ Branch 853 taken 25 times.
✗ Branch 854 not taken.
✗ Branch 855 not taken.
✗ Branch 856 not taken.
✗ Branch 857 not taken.
✗ Branch 858 not taken.
✗ Branch 859 not taken.
✗ Branch 860 not taken.
✗ Branch 861 not taken.
✗ Branch 862 not taken.
✗ Branch 863 not taken.
✗ Branch 864 not taken.
✗ Branch 865 not taken.
✗ Branch 866 not taken.
✗ Branch 867 not taken.
✗ Branch 868 not taken.
✗ Branch 869 not taken.
✗ Branch 870 not taken.
✗ Branch 871 not taken.
✗ Branch 872 not taken.
✗ Branch 873 not taken.
✗ Branch 874 not taken.
✗ Branch 875 not taken.
✗ Branch 876 not taken.
✗ Branch 877 not taken.
✗ Branch 878 not taken.
✗ Branch 879 not taken.
✗ Branch 880 not taken.
✗ Branch 881 not taken.
✗ Branch 882 not taken.
✗ Branch 883 not taken.
✗ Branch 884 not taken.
✗ Branch 885 not taken.
✗ Branch 886 not taken.
✗ Branch 887 not taken.
✗ Branch 888 not taken.
✗ Branch 889 not taken.
✗ Branch 890 not taken.
✗ Branch 891 not taken.
✗ Branch 892 not taken.
✗ Branch 893 not taken.
✗ Branch 894 not taken.
✓ Branch 895 taken 11602 times.
✗ Branch 896 not taken.
✗ Branch 897 not taken.
✗ Branch 898 not taken.
✗ Branch 899 not taken.
✗ Branch 900 not taken.
✗ Branch 901 not taken.
✗ Branch 902 not taken.
✗ Branch 903 not taken.
✗ Branch 904 not taken.
✗ Branch 905 not taken.
✗ Branch 906 not taken.
✗ Branch 907 not taken.
✗ Branch 908 not taken.
✗ Branch 909 not taken.
✗ Branch 910 not taken.
✗ Branch 911 not taken.
✗ Branch 912 not taken.
✗ Branch 913 not taken.
✗ Branch 914 not taken.
✗ Branch 915 not taken.
✗ Branch 916 not taken.
✗ Branch 917 not taken.
✗ Branch 918 not taken.
✗ Branch 919 not taken.
✗ Branch 920 not taken.
✗ Branch 921 not taken.
✗ Branch 922 not taken.
✗ Branch 923 not taken.
✗ Branch 924 not taken.
✗ Branch 925 not taken.
✗ Branch 926 not taken.
✗ Branch 927 not taken.
✗ Branch 928 not taken.
✗ Branch 929 not taken.
✗ Branch 930 not taken.
✗ Branch 931 not taken.
✗ Branch 932 not taken.
✗ Branch 933 not taken.
✗ Branch 934 not taken.
✗ Branch 935 not taken.
✗ Branch 936 not taken.
✗ Branch 937 not taken.
✗ Branch 938 not taken.
✗ Branch 939 not taken.
✗ Branch 940 not taken.
✗ Branch 941 not taken.
✗ Branch 942 not taken.
✗ Branch 943 not taken.
✗ Branch 944 not taken.
✗ Branch 945 not taken.
✗ Branch 946 not taken.
✗ Branch 947 not taken.
✗ Branch 948 not taken.
✗ Branch 949 not taken.
✗ Branch 950 not taken.
✗ Branch 951 not taken.
✗ Branch 952 not taken.
✗ Branch 953 not taken.
✗ Branch 954 not taken.
✗ Branch 955 not taken.
✗ Branch 956 not taken.
✗ Branch 957 not taken.
✗ Branch 958 not taken.
✗ Branch 959 not taken.
✗ Branch 960 not taken.
✗ Branch 961 not taken.
✗ Branch 962 not taken.
✗ Branch 963 not taken.
✗ Branch 964 not taken.
✗ Branch 965 not taken.
✓ Branch 966 taken 3182 times.
✗ Branch 967 not taken.
✗ Branch 968 not taken.
✗ Branch 969 not taken.
✗ Branch 970 not taken.
✓ Branch 971 taken 3182 times.
✗ Branch 972 not taken.
✗ Branch 973 not taken.
✗ Branch 974 not taken.
✗ Branch 975 not taken.
✗ Branch 976 not taken.
✗ Branch 977 not taken.
✗ Branch 978 not taken.
✗ Branch 979 not taken.
✗ Branch 980 not taken.
✗ Branch 981 not taken.
✗ Branch 982 not taken.
✗ Branch 983 not taken.
✗ Branch 984 not taken.
✗ Branch 985 not taken.
✗ Branch 986 not taken.
✓ Branch 987 taken 1 times.
✗ Branch 988 not taken.
✗ Branch 989 not taken.
✗ Branch 990 not taken.
✗ Branch 991 not taken.
✗ Branch 992 not taken.
✗ Branch 993 not taken.
✗ Branch 994 not taken.
✗ Branch 995 not taken.
✗ Branch 996 not taken.
✗ Branch 997 not taken.
✗ Branch 998 not taken.
✗ Branch 999 not taken.
✗ Branch 1000 not taken.
✗ Branch 1001 not taken.
✗ Branch 1002 not taken.
✗ Branch 1003 not taken.
✗ Branch 1004 not taken.
✗ Branch 1005 not taken.
✗ Branch 1006 not taken.
✗ Branch 1007 not taken.
✗ Branch 1008 not taken.
✗ Branch 1009 not taken.
✗ Branch 1010 not taken.
✗ Branch 1011 not taken.
✗ Branch 1012 not taken.
✗ Branch 1013 not taken.
✗ Branch 1014 not taken.
✗ Branch 1015 not taken.
✗ Branch 1016 not taken.
✗ Branch 1017 not taken.
✗ Branch 1018 not taken.
✓ Branch 1019 taken 10 times.
✗ Branch 1020 not taken.
✗ Branch 1021 not taken.
✗ Branch 1022 not taken.
✗ Branch 1023 not taken.
✗ Branch 1024 not taken.
✗ Branch 1025 not taken.
✓ Branch 1026 taken 3453 times.
✗ Branch 1027 not taken.
✗ Branch 1028 not taken.
✗ Branch 1029 not taken.
✗ Branch 1030 not taken.
✗ Branch 1031 not taken.
✗ Branch 1032 not taken.
✗ Branch 1033 not taken.
✓ Branch 1034 taken 26646 times.
✓ Branch 1035 taken 608462 times.
✓ Branch 1036 taken 5613429 times.
✓ Branch 1037 taken 1561191 times.
✓ Branch 1038 taken 4923553 times.
✓ Branch 1039 taken 27873688 times.
✗ Branch 1040 not taken.
✗ Branch 1041 not taken.
✗ Branch 1042 not taken.
✓ Branch 1043 taken 215684 times.
✓ Branch 1044 taken 16 times.
✓ Branch 1045 taken 8 times.
✓ Branch 1046 taken 1 times.
✓ Branch 1047 taken 72917 times.
✗ Branch 1048 not taken.
✓ Branch 1049 taken 24 times.
✗ Branch 1050 not taken.
✓ Branch 1051 taken 10 times.
✗ Branch 1052 not taken.
✗ Branch 1053 not taken.
✓ Branch 1054 taken 137691 times.
✗ Branch 1055 not taken.
✗ Branch 1056 not taken.
✗ Branch 1057 not taken.
✗ Branch 1058 not taken.
✗ Branch 1059 not taken.
✗ Branch 1060 not taken.
✗ Branch 1061 not taken.
✗ Branch 1062 not taken.
✗ Branch 1063 not taken.
✗ Branch 1064 not taken.
✗ Branch 1065 not taken.
✗ Branch 1066 not taken.
✗ Branch 1067 not taken.
✓ Branch 1068 taken 36 times.
✗ Branch 1069 not taken.
✗ Branch 1070 not taken.
✗ Branch 1071 not taken.
✗ Branch 1072 not taken.
✓ Branch 1073 taken 500 times.
✓ Branch 1074 taken 120 times.
✗ Branch 1075 not taken.
✓ Branch 1076 taken 8 times.
✓ Branch 1077 taken 63 times.
✗ Branch 1078 not taken.
✓ Branch 1079 taken 5 times.
✗ Branch 1080 not taken.
✗ Branch 1081 not taken.
✗ Branch 1082 not taken.
✗ Branch 1083 not taken.
✗ Branch 1084 not taken.
✓ Branch 1085 taken 5144 times.
✗ Branch 1086 not taken.
✗ Branch 1087 not taken.
✗ Branch 1088 not taken.
✗ Branch 1089 not taken.
✓ Branch 1090 taken 8254411 times.
✗ Branch 1091 not taken.
✗ Branch 1092 not taken.
✗ Branch 1093 not taken.
✗ Branch 1094 not taken.
✗ Branch 1095 not taken.
✗ Branch 1096 not taken.
✗ Branch 1097 not taken.
✗ Branch 1098 not taken.
✗ Branch 1099 not taken.
✗ Branch 1100 not taken.
✗ Branch 1101 not taken.
✗ Branch 1102 not taken.
✗ Branch 1103 not taken.
✗ Branch 1104 not taken.
✗ Branch 1105 not taken.
✗ Branch 1106 not taken.
✗ Branch 1107 not taken.
✗ Branch 1108 not taken.
✗ Branch 1109 not taken.
✗ Branch 1110 not taken.
✗ Branch 1111 not taken.
✗ Branch 1112 not taken.
✗ Branch 1113 not taken.
✗ Branch 1114 not taken.
✗ Branch 1115 not taken.
✗ Branch 1116 not taken.
✗ Branch 1117 not taken.
✗ Branch 1118 not taken.
✗ Branch 1119 not taken.
✓ Branch 1120 taken 14124 times.
✗ Branch 1121 not taken.
✗ Branch 1122 not taken.
✗ Branch 1123 not taken.
✓ Branch 1124 taken 54674 times.
✓ Branch 1125 taken 11 times.
✓ Branch 1126 taken 49958 times.
✗ Branch 1127 not taken.
✗ Branch 1128 not taken.
✗ Branch 1129 not taken.
✗ Branch 1130 not taken.
✗ Branch 1131 not taken.
✗ Branch 1132 not taken.
✗ Branch 1133 not taken.
✗ Branch 1134 not taken.
✗ Branch 1135 not taken.
✗ Branch 1136 not taken.
✗ Branch 1137 not taken.
✗ Branch 1138 not taken.
✗ Branch 1139 not taken.
✗ Branch 1140 not taken.
✗ Branch 1141 not taken.
✗ Branch 1142 not taken.
✗ Branch 1143 not taken.
✗ Branch 1144 not taken.
✗ Branch 1145 not taken.
✗ Branch 1146 not taken.
✗ Branch 1147 not taken.
✗ Branch 1148 not taken.
✗ Branch 1149 not taken.
✗ Branch 1150 not taken.
✗ Branch 1151 not taken.
✓ Branch 1152 taken 5031 times.
✗ Branch 1153 not taken.
✗ Branch 1154 not taken.
✗ Branch 1155 not taken.
✗ Branch 1156 not taken.
✗ Branch 1157 not taken.
✗ Branch 1158 not taken.
✓ Branch 1159 taken 1005 times.
✓ Branch 1160 taken 2475 times.
✗ Branch 1161 not taken.
✓ Branch 1162 taken 17326 times.
✓ Branch 1163 taken 6024 times.
✗ Branch 1164 not taken.
✓ Branch 1165 taken 4206 times.
✓ Branch 1166 taken 9836 times.
✗ Branch 1167 not taken.
✗ Branch 1168 not taken.
✗ Branch 1169 not taken.
✗ Branch 1170 not taken.
✓ Branch 1171 taken 339 times.
✓ Branch 1172 taken 339 times.
✗ Branch 1173 not taken.
✗ Branch 1174 not taken.
✗ Branch 1175 not taken.
✗ Branch 1176 not taken.
✗ Branch 1177 not taken.
✗ Branch 1178 not taken.
✗ Branch 1179 not taken.
✗ Branch 1180 not taken.
✗ Branch 1181 not taken.
✗ Branch 1182 not taken.
✗ Branch 1183 not taken.
✗ Branch 1184 not taken.
✗ Branch 1185 not taken.
✗ Branch 1186 not taken.
✗ Branch 1187 not taken.
✗ Branch 1188 not taken.
✗ Branch 1189 not taken.
✗ Branch 1190 not taken.
✗ Branch 1191 not taken.
✗ Branch 1192 not taken.
✗ Branch 1193 not taken.
✗ Branch 1194 not taken.
✗ Branch 1195 not taken.
✗ Branch 1196 not taken.
✗ Branch 1197 not taken.
✗ Branch 1198 not taken.
✗ Branch 1199 not taken.
✗ Branch 1200 not taken.
✗ Branch 1201 not taken.
✗ Branch 1202 not taken.
✗ Branch 1203 not taken.
✗ Branch 1204 not taken.
✗ Branch 1205 not taken.
✗ Branch 1206 not taken.
✗ Branch 1207 not taken.
✗ Branch 1208 not taken.
✗ Branch 1209 not taken.
✗ Branch 1210 not taken.
✗ Branch 1211 not taken.
✗ Branch 1212 not taken.
✗ Branch 1213 not taken.
✗ Branch 1214 not taken.
✗ Branch 1215 not taken.
✗ Branch 1216 not taken.
✗ Branch 1217 not taken.
✗ Branch 1218 not taken.
✗ Branch 1219 not taken.
✗ Branch 1220 not taken.
✗ Branch 1221 not taken.
✗ Branch 1222 not taken.
✗ Branch 1223 not taken.
✗ Branch 1224 not taken.
✗ Branch 1225 not taken.
✗ Branch 1226 not taken.
✗ Branch 1227 not taken.
✗ Branch 1228 not taken.
✗ Branch 1229 not taken.
✗ Branch 1230 not taken.
✗ Branch 1231 not taken.
✗ Branch 1232 not taken.
✗ Branch 1233 not taken.
✓ Branch 1234 taken 1455 times.
✗ Branch 1235 not taken.
✗ Branch 1236 not taken.
✗ Branch 1237 not taken.
✗ Branch 1238 not taken.
✗ Branch 1239 not taken.
✗ Branch 1240 not taken.
✗ Branch 1241 not taken.
✗ Branch 1242 not taken.
✗ Branch 1243 not taken.
✗ Branch 1244 not taken.
✗ Branch 1245 not taken.
✗ Branch 1246 not taken.
✗ Branch 1247 not taken.
✗ Branch 1248 not taken.
✗ Branch 1249 not taken.
✗ Branch 1250 not taken.
✗ Branch 1251 not taken.
✗ Branch 1252 not taken.
✗ Branch 1253 not taken.
✗ Branch 1254 not taken.
2846197516 switch(arg)
2836 {
2837 case MAX_FFC_ID:
2838 {
2839 3175230 ret = (MAX_FFCID + 1) * 10000;
2840 3175230 break;
2841 }
2842
2843 case INCQST:
2844 {
2845 int32_t newqst = 0;
2846 if ( game->get_quest() < 255 ) //255 is a custom quest
2847 {
2848 newqst = (game->get_quest()+1);
2849 }
2850 else
2851 {
2852 newqst = 1;
2853 }
2854 if ( newqst < 11 )
2855 {
2856
2857 ret = newqst * 10000;
2858 Quit = qINCQST;
2859 //ending();
2860
2861 }
2862 else ret = -10000;
2863 break;
2864 }
2865 //Debug->Null()
2866 case DONULL:
2867 ret = 0;
2868 break;
2869 case DEBUGTESTING:
2870 623627 ret = use_testingst_start ? 10000 : 0;
2871 623627 break;
2872
2873 //debug ri->d[]
2874 case DEBUGD:
2875 {
2876 int32_t a = ri->d[rINDEX] / 10000;
2877 ret = ri->d[a] * 10000;
2878 break;
2879 }
2880
2881 ///----------------------------------------------------------------------------------------------------//
2882 //FFC Variables
2883 case DATA:
2884
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 13052060 times.
13052062 if (auto ffc = ResolveFFC(ri->ffcref))
2885 13052060 ret = ffc->data * 10000;
2886 13052062 break;
2887
2888 case FFSCRIPT:
2889
2/2
✓ Branch 0 taken 531424776 times.
✓ Branch 1 taken 212 times.
531424988 if(auto ffc = ResolveFFC(ri->ffcref))
2890 531424776 ret = ffc->script * 10000;
2891 531424988 break;
2892
2893 case FCSET:
2894
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2312685 times.
2312685 if(auto ffc = ResolveFFC(ri->ffcref))
2895 2312685 ret = ffc->cset * 10000;
2896 2312685 break;
2897
2898 case DELAY:
2899
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(auto ffc = ResolveFFC(ri->ffcref))
2900 10 ret = ffc->delay * 10000;
2901 10 break;
2902
2903 case FX:
2904
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24185371 times.
24185371 if(auto ffc = ResolveFFC(ri->ffcref))
2905 24185371 ret = ffc->x.getZLong();
2906 24185371 break;
2907
2908 case FY:
2909
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23746251 times.
23746251 if(auto ffc = ResolveFFC(ri->ffcref))
2910 23746251 ret = ffc->y.getZLong();
2911 23746251 break;
2912
2913 case XD:
2914
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5823966 times.
5823966 if(auto ffc = ResolveFFC(ri->ffcref))
2915 5823966 ret = ffc->vx.getZLong();
2916 5823966 break;
2917
2918 case YD:
2919
1/2
✓ Branch 0 taken 163102 times.
✗ Branch 1 not taken.
163102 if(auto ffc = ResolveFFC(ri->ffcref))
2920 163102 ret = ffc->vy.getZLong();
2921 163102 break;
2922 case FFCID:
2923
1/2
✓ Branch 0 taken 375 times.
✗ Branch 1 not taken.
375 if (auto ffc = ResolveFFC(ri->ffcref))
2924 375 ret = (get_region_screen_offset(ffc->screen_spawned) * MAXFFCS + ffc->index + 1) * 10000;
2925 375 break;
2926
2927 case XD2:
2928
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if(auto ffc = ResolveFFC(ri->ffcref))
2929 51 ret = ffc->ax.getZLong();
2930 51 break;
2931
2932 case YD2:
2933
1/2
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
51 if(auto ffc = ResolveFFC(ri->ffcref))
2934 51 ret = ffc->ay.getZLong();
2935 51 break;
2936
2937 case FFFLAGSD:
2938
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4291571 times.
4291571 if(auto ffc = ResolveFFC(ri->ffcref))
2939 4291571 ret = (ffc->flags >> (ri->d[rINDEX] / 10000)) & 1 ? 10000 : 0;
2940 4291571 break;
2941
2942 case FFCWIDTH:
2943
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 204076 times.
204076 if(auto ffc = ResolveFFC(ri->ffcref))
2944 204076 ret = ffc->hit_width * 10000;
2945 204076 break;
2946
2947 case FFCHEIGHT:
2948
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 199035 times.
199035 if(auto ffc = ResolveFFC(ri->ffcref))
2949 199035 ret = ffc->hit_height * 10000;
2950 199035 break;
2951
2952 case FFTWIDTH:
2953
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5283857 times.
5283857 if(auto ffc = ResolveFFC(ri->ffcref))
2954 5283857 ret = ffc->txsz * 10000;
2955 5283857 break;
2956
2957 case FFTHEIGHT:
2958
1/2
✓ Branch 0 taken 5194596 times.
✗ Branch 1 not taken.
5194596 if(auto ffc = ResolveFFC(ri->ffcref))
2959 5194596 ret = ffc->tysz * 10000;
2960 5194596 break;
2961
2962 case FFCLAYER:
2963 if (auto ffc = ResolveFFC(ri->ffcref))
2964 ret = ffc->layer * 10000;
2965 break;
2966
2967 case FFLINK:
2968 if(auto ffc = ResolveFFC(ri->ffcref))
2969 ret = ffc->link * 10000;
2970 break;
2971
2972 case FFMISCD:
2973 {
2974 18378384 int32_t a = ri->d[rINDEX] / 10000;
2975
2976
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18378384 times.
18378384 if(BC::checkMisc(a) != SH::_NoError)
2977 ret = -10000;
2978 else
2979 {
2980
1/2
✓ Branch 0 taken 18378384 times.
✗ Branch 1 not taken.
18378384 if(auto ffc = ResolveFFC(ri->ffcref))
2981 18378384 ret = ffc->miscellaneous[a];
2982 }
2983 }
2984 18378384 break;
2985
2986 case FFINITDD:
2987 {
2988 231939 int32_t a = ri->d[rINDEX] / 10000;
2989
2990
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 231939 times.
231939 if(BC::checkIndex(a, 0, 7) != SH::_NoError)
2991 ret = -10000;
2992 else
2993 {
2994
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 231922 times.
231939 if(auto ffc = ResolveFFC(ri->ffcref))
2995 231922 ret = ffc->initd[a];
2996 }
2997 }
2998 231939 break;
2999
3000 ///----------------------------------------------------------------------------------------------------//
3001 //Hero's Variables
3002 case LINKX:
3003 {
3004
2/2
✓ Branch 0 taken 8938966 times.
✓ Branch 1 taken 32842205 times.
41781171 if (get_qr(qr_SPRITEXY_IS_FLOAT))
3005 {
3006 8938966 ret = Hero.getX().getZLong();
3007 8938966 }
3008 32842205 else ret = int32_t(Hero.getX()) * 10000;
3009
3010 41781171 break;
3011 }
3012
3013 case LINKCSET:
3014 {
3015 ret = Hero.cs * 10000;
3016 break;
3017 }
3018 case LINKY:
3019 {
3020
2/2
✓ Branch 0 taken 9752728 times.
✓ Branch 1 taken 32915641 times.
42668369 if (get_qr(qr_SPRITEXY_IS_FLOAT))
3021 {
3022 9752728 ret = Hero.getY().getZLong();
3023 9752728 }
3024 32915641 else ret = int32_t(Hero.getY()) * 10000;
3025
3026 42668369 break;
3027 }
3028 case LINKZ:
3029 {
3030
2/2
✓ Branch 0 taken 2847194 times.
✓ Branch 1 taken 1173487 times.
4020681 if (get_qr(qr_SPRITEXY_IS_FLOAT))
3031 {
3032 2847194 ret = Hero.getZ().getZLong();
3033 2847194 }
3034 1173487 else ret = int32_t(Hero.getZ()) * 10000;
3035
3036 4020681 break;
3037 }
3038 case LINKJUMP:
3039 // -fall/100*10000, but doing it that way screwed up the result
3040 719568 ret = Hero.getFall().getZLong() / -100;
3041 719568 break;
3042
3043 case HEROFAKEJUMP:
3044 ret = Hero.getFakeFall().getZLong() / -100;
3045 break;
3046
3047 case LINKDIR:
3048 9094315 ret=(int32_t)(Hero.dir)*10000;
3049 9094315 break;
3050
3051 case LINKHITDIR:
3052 441276 ret=(int32_t)(Hero.getHitDir())*10000;
3053 441276 break;
3054
3055 case LINKHP:
3056 24132812 ret=(int32_t)(game->get_life())*10000;
3057 24132812 break;
3058
3059 case LINKGRAVITY:
3060 ret = ( (Hero.moveflags & move_obeys_grav) ? 10000 : 0 );
3061 break;
3062
3063 case HERONOSTEPFORWARD:
3064 ret = ( (FFCore.nostepforward) ? 10000 : 0 );
3065 break;
3066
3067 case LINKMP:
3068 2790135 ret=(int32_t)(game->get_magic())*10000;
3069 2790135 break;
3070
3071 case LINKMAXHP:
3072 1061314 ret=(int32_t)(game->get_maxlife())*10000;
3073 1061314 break;
3074
3075 case LINKMAXMP:
3076 944827 ret=(int32_t)(game->get_maxmagic())*10000;
3077 944827 break;
3078
3079 case LINKACTION:
3080 {
3081 78365820 ret = FFCore.getHeroAction() * 10000;
3082 78365820 break;
3083 }
3084
3085 case HEROHEALTHBEEP:
3086 {
3087 ret = heart_beep ? ( heart_beep_timer * 10000 ) : 0;
3088 break;
3089 }
3090
3091 case LINKHELD:
3092 204 ret = (int32_t)(Hero.getHeldItem())*10000;
3093 204 break;
3094
3095 case LINKITEMD:
3096 23758768 ret = game->item[vbound(ri->d[rINDEX]/10000, 0, MAXITEMS-1)] ? 10000 : 0;
3097 23758768 break;
3098
3099 case HEROSTEPS:
3100 ret = lsteps[vbound(ri->d[rINDEX]/10000, 0, 7)] * 10000;
3101 break;
3102
3103 case HEROSTEPRATE:
3104 5424 ret = Hero.getStepRate() * 10000;
3105 5424 break;
3106 case HEROSHOVEOFFSET:
3107 ret = Hero.shove_offset.getZLong();
3108 break;
3109
3110 case LINKEQUIP:
3111 1249005 ret = ((Awpn&0xFF)|((Bwpn&0xFF)<<8))*10000;
3112 1249005 break;
3113
3114 case LINKINVIS:
3115 573955 ret = (((int32_t)(Hero.getDontDraw())) ? 10000 : 0);
3116 573955 break;
3117
3118 case LINKINVINC:
3119 652486 ret = (int32_t)(Hero.scriptcoldet)*10000;
3120 652486 break;
3121
3122 case LINKENGINEANIMATE:
3123 ret = (int32_t)(Hero.do_animation)*10000;
3124 break;
3125
3126 case LINKLADDERX:
3127 ret=(int32_t)(Hero.getLadderX())*10000;
3128 break;
3129
3130 case LINKLADDERY:
3131 ret=(int32_t)(Hero.getLadderY())*10000;
3132 break;
3133
3134 case LINKSWORDJINX:
3135 959935 ret = (int32_t)(Hero.getSwordClk())*10000;
3136 959935 break;
3137
3138 case LINKITEMJINX:
3139 1095514 ret = (int32_t)(Hero.getItemClk())*10000;
3140 1095514 break;
3141
3142 case LINKDRUNK:
3143 ret = (int32_t)(Hero.DrunkClock())*10000;
3144 break;
3145
3146 case LINKMISCD:
3147 7337405 ret = (int32_t)(Hero.miscellaneous[vbound(ri->d[rINDEX]/10000,0,31)]); //Was this buffed before? -Z
3148 7337405 break;
3149
3150
3151 case LINKHITBY:
3152 {
3153 3244 int32_t indx = ri->d[rINDEX]/10000;
3154
1/3
✓ Branch 0 taken 3244 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
3244 switch(indx)
3155 {
3156 //screen indices of objects
3157 case 0:
3158 case 1:
3159 case 2:
3160 case 3:
3161 case 8:
3162 case 9:
3163 case 10:
3164 case 11:
3165 case 12:
3166 case 16:
3167 {
3168 3244 ret = (int32_t)(Hero.gethitHeroUID(indx))* 10000;
3169 3244 break;
3170 }
3171 //uids of objects
3172 case 4:
3173 case 5:
3174 case 6:
3175 case 7:
3176 case 13:
3177 case 14:
3178 case 15:
3179 {
3180 ret = (int32_t)(Hero.gethitHeroUID(indx)); //do not multiply by 10000! UIDs are not *10000!
3181 break;
3182 }
3183 default: { Z_scripterrlog("Invalid index passed to Hero->HitBy[%d]/n", indx); ret = -1; break; }
3184 }
3185 3244 break;
3186 }
3187 case LINKDEFENCE:
3188 ret = (int32_t)(Hero.get_defence(vbound(ri->d[rINDEX]/10000,0,255)))* 10000;
3189 break;
3190
3191
3192 case LINKROTATION:
3193 if ( get_qr(qr_OLDSPRITEDRAWS) )
3194 {
3195 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
3196 ret = -1; break;
3197 }
3198 ret = (int32_t)(Hero.rotation)*10000;
3199 break;
3200
3201 case LINKSCALE:
3202 {
3203 if ( get_qr(qr_OLDSPRITEDRAWS) )
3204 {
3205 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
3206 ret = -1; break;
3207 }
3208 ret = (int32_t)(Hero.scale*100.0);
3209 break;
3210 }
3211
3212
3213 case LINKHXOFS:
3214 656387 ret = (int32_t)(Hero.hxofs)*10000;
3215 656387 break;
3216
3217 case LINKHYOFS:
3218 571655 ret = (int32_t)(Hero.hyofs)*10000;
3219 571655 break;
3220
3221 case LINKXOFS:
3222 113145 ret = (int32_t)(Hero.xofs)*10000;
3223 113145 break;
3224
3225 case LINKYOFS:
3226
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 115547 times.
115547 ret = (int32_t)(Hero.yofs-(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset))*10000;
3227 115547 break;
3228
3229 case HEROSHADOWXOFS:
3230 ret = (int32_t)(Hero.shadowxofs)*10000;
3231 break;
3232
3233 case HEROSHADOWYOFS:
3234 ret = (int32_t)(Hero.shadowyofs)*10000;
3235 break;
3236
3237 case HEROTOTALDYOFFS:
3238 ret = 10000*(((int32_t)(Hero.yofs-(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset)))
3239 + ((Hero.switch_hooked && Hero.switchhookstyle == swRISE)
3240 ? -(8-(abs(Hero.switchhookclk-32)/4)) : 0));
3241 break;
3242
3243 case LINKZOFS:
3244 ret = (int32_t)(Hero.zofs)*10000;
3245 break;
3246
3247 case LINKHXSZ:
3248 489104 ret = (int32_t)(Hero.hit_width)*10000;
3249 489104 break;
3250
3251 case LINKHYSZ:
3252 489104 ret = (int32_t)(Hero.hit_height)*10000;
3253 489104 break;
3254
3255 case LINKHZSZ:
3256 288295 ret = (int32_t)(Hero.hzsz)*10000;
3257 288295 break;
3258
3259 case LINKTXSZ:
3260 ret = (int32_t)(Hero.txsz)*10000;
3261 break;
3262
3263 case LINKTYSZ:
3264 ret = (int32_t)(Hero.tysz)*10000;
3265 break;
3266
3267 case LINKTILE:
3268 4101 ret = (int32_t)(Hero.tile)*10000;
3269 4101 break;
3270
3271 case LINKFLIP:
3272 ret = (int32_t)(Hero.flip)*10000;
3273 break;
3274
3275 case LINKINVFRAME:
3276 57322 ret = (int32_t)Hero.getHClk()*10000;
3277 57322 break;
3278
3279 case LINKCANFLICKER:
3280 ret= Hero.getCanFlicker()?10000:0;
3281 break;
3282 case LINKHURTSFX:
3283 ret = (int32_t)Hero.getHurtSFX()*10000;
3284 break;
3285
3286 /*
3287 case LINKUSINGITEM:
3288 ret = (int32_t)Hero.getDirectItem()*10000;
3289 break;
3290
3291 case LINKUSINGITEMA:
3292 ret = (int32_t)Hero.getDirectItemA()*10000;
3293 break;
3294
3295 case LINKUSINGITEMB:
3296 ret = (int32_t)Hero.getDirectItemB()*10000;
3297 break;
3298 */
3299
3300 case LINKEATEN:
3301 ret=(int32_t)Hero.getEaten()*10000;
3302 break;
3303 case LINKGRABBED:
3304 ret = Hero.inwallm ? 10000 : 0;
3305 break;
3306 case HEROBUNNY:
3307 ret = Hero.BunnyClock()*10000;
3308 break;
3309 case LINKPUSH:
3310 180367 ret=(int32_t)Hero.getPushing()*10000;
3311 180367 break;
3312 case LINKSTUN:
3313 440770 ret=(int32_t)Hero.StunClock()*10000;
3314 440770 break;
3315 case LINKSCRIPTTILE:
3316 2 ret=script_hero_sprite*10000;
3317 2 break;
3318
3319 case HEROSCRIPTCSET:
3320 ret=script_hero_cset*10000;
3321 break;
3322 case LINKSCRIPFLIP:
3323 ret=script_hero_flip*10000;
3324 break;
3325
3326
3327 case LINKITEMB:
3328 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
3329 428588 ret = Bwpn*10000;
3330 428588 break;
3331
3332 case LINKITEMA:
3333 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
3334 432590 ret = Awpn *10000;
3335 432590 break;
3336
3337 case LINKITEMX:
3338 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
3339 337110 ret = Xwpn *10000;
3340 337110 break;
3341
3342 case LINKITEMY:
3343 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
3344 273630 ret = Ywpn *10000;
3345 273630 break;
3346
3347 case LINKTILEMOD:
3348 ret = Hero.getTileModifier() * 10000;
3349 break;
3350
3351 case LINKDIAG:
3352 ret=Hero.getDiagMove()?10000:0;
3353 break;
3354
3355 case LINKBIGHITBOX:
3356 271788 ret=Hero.getBigHitbox()?10000:0;
3357 271788 break;
3358
3359 case LINKCLIMBING:
3360 ret = Hero.getOnSideviewLadder()?10000:0;
3361 break;
3362
3363 case HEROJUMPCOUNT:
3364 ret = Hero.extra_jump_count * 10000;
3365 break;
3366
3367 case HEROPULLDIR:
3368 ret = Hero.pit_pulldir * 10000;
3369 break;
3370
3371 case HEROPULLCLK:
3372 ret = Hero.pit_pullclk * 10000;
3373 break;
3374
3375 case HEROFALLCLK:
3376 832354 ret = Hero.fallclk * 10000;
3377 832354 break;
3378
3379 case HEROFALLCMB:
3380 18 ret = Hero.fallCombo * 10000;
3381 18 break;
3382
3383 case HERODROWNCLK:
3384 ret = Hero.drownclk * 10000;
3385 break;
3386
3387 case HERODROWNCMB:
3388 ret = Hero.drownCombo * 10000;
3389 break;
3390
3391 case HEROFAKEZ:
3392 {
3393
1/2
✓ Branch 0 taken 4357 times.
✗ Branch 1 not taken.
4357 if (get_qr(qr_SPRITEXY_IS_FLOAT))
3394 {
3395 4357 ret = Hero.getFakeZ().getZLong();
3396 4357 }
3397 else ret = int32_t(Hero.getFakeZ()) * 10000;
3398
3399 4357 break;
3400 }
3401 case HEROMOVEFLAGS:
3402 {
3403 int32_t indx = ri->d[rINDEX]/10000;
3404 if(BC::checkIndex(indx, 0, 10) != SH::_NoError)
3405 ret = 0; //false
3406 else
3407 {
3408 //All bits, in order, of a single byte; just use bitwise
3409 ret = (Hero.moveflags & (1<<indx)) ? 10000 : 0;
3410 }
3411 break;
3412 }
3413 case HEROLIFTFLAGS:
3414 {
3415 int32_t indx = ri->d[rINDEX]/10000;
3416 if(BC::checkIndex(indx, 0, NUM_LIFTFL-1) != SH::_NoError)
3417 ret = 0; //false
3418 else
3419 {
3420 ret = (Hero.liftflags & (1<<indx)) ? 10000 : 0;
3421 }
3422 break;
3423 }
3424
3425 case HEROSHIELDJINX:
3426 ret = Hero.shieldjinxclk * 10000;
3427 break;
3428
3429 case HEROISWARPING:
3430 1012 ret = Hero.is_warping ? 10000L : 0L;
3431 1012 break;
3432
3433 case CLOCKACTIVE:
3434 ret=watch?10000:0;
3435 break;
3436
3437 case CLOCKCLK:
3438 ret=clockclk*10000;
3439 break;
3440
3441 case HERORESPAWNX:
3442 {
3443 ret = Hero.respawn_x.getZLong();
3444 break;
3445 }
3446
3447 case HERORESPAWNY:
3448 {
3449 ret = Hero.respawn_y.getZLong();
3450 break;
3451 }
3452
3453 case HERORESPAWNDMAP:
3454 {
3455 ret = Hero.respawn_dmap * 10000;
3456 break;
3457 }
3458
3459 case HERORESPAWNSCR:
3460 {
3461 ret = Hero.respawn_scr * 10000;
3462 break;
3463 }
3464
3465 case HEROSWITCHTIMER:
3466 {
3467 ret = Hero.switchhookclk * 10000;
3468 break;
3469 }
3470
3471 case HEROSWITCHMAXTIMER:
3472 {
3473 ret = Hero.switchhookmaxtime * 10000;
3474 break;
3475 }
3476
3477 case HEROIMMORTAL:
3478 {
3479 ret = Hero.immortal * 10000;
3480 break;
3481 }
3482
3483 case HEROSTANDING:
3484 {
3485 ret = Hero.isStanding(true) ? 10000 : 0;
3486 break;
3487 }
3488
3489 case HEROCOYOTETIME:
3490 {
3491 ret = Hero.coyotetime*10000;
3492 break;
3493 }
3494
3495 case HEROLIFTEDWPN:
3496 {
3497 ret = Hero.lift_wpn ? Hero.lift_wpn->getUID() : 0;
3498 break;
3499 }
3500 case HEROLIFTTIMER:
3501 {
3502 ret = Hero.liftclk * 10000;
3503 break;
3504 }
3505 case HEROLIFTMAXTIMER:
3506 {
3507 ret = Hero.tliftclk * 10000;
3508 break;
3509 }
3510 case HEROLIFTHEIGHT:
3511 {
3512 ret = Hero.liftheight.getZLong();
3513 break;
3514 }
3515 case HEROHAMMERSTATE:
3516 {
3517 ret = Hero.getHammerState() * 10000;
3518 break;
3519 }
3520 case HEROFLICKERCOLOR:
3521 ret = (int32_t)(Hero.flickercolor) * 10000; break;
3522 case HEROFLASHINGCSET:
3523 136185 ret = (int32_t)(Hero.getFlashingCSet()) * 10000; break;
3524 case HEROFLICKERTRANSP:
3525 ret = (int32_t)(Hero.flickertransp) * 10000; break;
3526
3527 case HEROSLIDING:
3528 ret = Hero.sliding*10000; break;
3529 case HEROICECMB:
3530 ret = Hero.ice_combo*10000; break;
3531 case HEROSCRICECMB:
3532 ret = Hero.script_ice_combo*10000; break;
3533 case HEROICEVX:
3534 ret = Hero.ice_vx.getZLong(); break;
3535 case HEROICEVY:
3536 ret = Hero.ice_vy.getZLong(); break;
3537 case HEROICEENTRYFRAMES:
3538 ret = Hero.ice_entry_count*10000; break;
3539 case HEROICEENTRYMAXFRAMES:
3540 ret = Hero.ice_entry_mcount*10000; break;
3541
3542 ///----------------------------------------------------------------------------------------------------//
3543 //Input States
3544 case INPUTSTART:
3545 92967 ret=control_state[6]?10000:0;
3546 92967 break;
3547
3548 case INPUTMAP:
3549 4123 ret=control_state[9]?10000:0;
3550 4123 break;
3551
3552 case INPUTUP:
3553 4321356 ret=control_state[0]?10000:0;
3554 4321356 break;
3555
3556 case INPUTDOWN:
3557 3824036 ret=control_state[1]?10000:0;
3558 3824036 break;
3559
3560 case INPUTLEFT:
3561 4211785 ret=control_state[2]?10000:0;
3562 4211785 break;
3563
3564 case INPUTRIGHT:
3565 4388042 ret=control_state[3]?10000:0;
3566 4388042 break;
3567
3568 case INPUTA:
3569 6701954 ret=control_state[4]?10000:0;
3570 6701954 break;
3571
3572 case INPUTB:
3573 5699839 ret=control_state[5]?10000:0;
3574 5699839 break;
3575
3576 case INPUTL:
3577 3218568 ret=control_state[7]?10000:0;
3578 3218568 break;
3579
3580 case INPUTR:
3581 3214309 ret=control_state[8]?10000:0;
3582 3214309 break;
3583
3584 case INPUTEX1:
3585 120159 ret=control_state[10]?10000:0;
3586 120159 break;
3587
3588 case INPUTEX2:
3589 120450 ret=control_state[11]?10000:0;
3590 120450 break;
3591
3592 case INPUTEX3:
3593 23391 ret=control_state[12]?10000:0;
3594 23391 break;
3595
3596 case INPUTEX4:
3597 23391 ret=control_state[13]?10000:0;
3598 23391 break;
3599
3600 case INPUTAXISUP:
3601 ret=control_state[14]?10000:0;
3602 break;
3603
3604 case INPUTAXISDOWN:
3605 ret=control_state[15]?10000:0;
3606 break;
3607
3608 case INPUTAXISLEFT:
3609 ret=control_state[16]?10000:0;
3610 break;
3611
3612 case INPUTAXISRIGHT:
3613 ret=control_state[17]?10000:0;
3614 break;
3615
3616 case INPUTMOUSEX:
3617 {
3618 791031 ret=get_mouse_state(0)*10000;
3619 791031 break;
3620 }
3621
3622 case INPUTMOUSEY:
3623 {
3624 791031 int32_t mousequakeoffset = 56+((int32_t)(zc::math::Sin((double)(quakeclk*int64_t(2)-frame))*4));
3625
3/4
✓ Branch 0 taken 24219 times.
✓ Branch 1 taken 766812 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 766812 times.
791031 int32_t tempoffset = (quakeclk > 0) ? mousequakeoffset : (get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset);
3626 791031 ret=((get_mouse_state(1)-tempoffset))*10000;
3627 791031 break;
3628 }
3629
3630 case INPUTMOUSEZ:
3631 ret=(get_mouse_state(2))*10000;
3632 break;
3633
3634 case INPUTMOUSEB:
3635 1073638 ret=(get_mouse_state(3))*10000;
3636 1073638 break;
3637
3638 case INPUTPRESSSTART:
3639 818518 ret=button_press[6]?10000:0;
3640 818518 break;
3641
3642 case INPUTPRESSMAP:
3643 335732 ret=button_press[9]?10000:0;
3644 335732 break;
3645
3646 case INPUTPRESSUP:
3647 1118025 ret=button_press[0]?10000:0;
3648 1118025 break;
3649
3650 case INPUTPRESSDOWN:
3651 1056398 ret=button_press[1]?10000:0;
3652 1056398 break;
3653
3654 case INPUTPRESSLEFT:
3655 963357 ret=button_press[2]?10000:0;
3656 963357 break;
3657
3658 case INPUTPRESSRIGHT:
3659 870340 ret=button_press[3]?10000:0;
3660 870340 break;
3661
3662 case INPUTPRESSA:
3663 2442823 ret=button_press[4]?10000:0;
3664 2442823 break;
3665
3666 case INPUTPRESSB:
3667 1811399 ret=button_press[5]?10000:0;
3668 1811399 break;
3669
3670 case INPUTPRESSL:
3671 2061226 ret=button_press[7]?10000:0;
3672 2061226 break;
3673
3674 case INPUTPRESSR:
3675 1845780 ret=button_press[8]?10000:0;
3676 1845780 break;
3677
3678 case INPUTPRESSEX1:
3679 1237553 ret=button_press[10]?10000:0;
3680 1237553 break;
3681
3682 case INPUTPRESSEX2:
3683 1081361 ret=button_press[11]?10000:0;
3684 1081361 break;
3685
3686 case INPUTPRESSEX3:
3687 558264 ret=button_press[12]?10000:0;
3688 558264 break;
3689
3690 case INPUTPRESSEX4:
3691 669416 ret=button_press[13]?10000:0;
3692 669416 break;
3693
3694 case PRESSAXISUP:
3695 ret=button_press[14]?10000:0;
3696 break;
3697
3698 case PRESSAXISDOWN:
3699 ret=button_press[15]?10000:0;
3700 break;
3701
3702 case PRESSAXISLEFT:
3703 ret=button_press[16]?10000:0;
3704 break;
3705
3706 case PRESSAXISRIGHT:
3707 ret=button_press[17]?10000:0;
3708 break;
3709
3710 case FFRULE:
3711 {
3712 4870 int32_t ruleid = vbound((ri->d[rINDEX]/10000),0,qr_MAX);
3713 4870 ret = get_qr(ruleid)?10000:0;
3714 }
3715 4870 break;
3716
3717 case BUTTONPRESS:
3718 // DUkey, DDkey, DLkey, DRkey, Akey, Bkey, Skey, Lkey, Rkey, Pkey, Exkey1, Exkey2, Exkey3, Exkey4 };
3719 {
3720 //Read-only
3721 286348 int32_t button = vbound((ri->d[rINDEX]/10000),0,17);
3722 286348 ret = button_press[button]?10000:0;
3723 }
3724 286348 break;
3725
3726 case BUTTONINPUT:
3727 {
3728 //Read-only
3729 672937 int32_t button = vbound((ri->d[rINDEX]/10000),0,17);
3730 672937 ret=control_state[button]?10000:0;
3731 }
3732 672937 break;
3733
3734 case BUTTONHELD:
3735 {
3736 //Read-only
3737 4686 int32_t button = vbound((ri->d[rINDEX]/10000),0,17);
3738 4686 ret = button_hold[button]?10000:0;
3739 }
3740 4686 break;
3741
3742 case RAWKEY:
3743 {
3744 bool pressed = read_array(key_current_frame, ri->d[rINDEX]/10000) != 0;
3745 ret = pressed?10000:0;
3746 }
3747 break;
3748
3749 case KEYINPUT:
3750 {
3751 1121 ret = read_array(KeyInput, ri->d[rINDEX]/10000) * 10000;
3752 1121 break;
3753 }
3754 case KEYPRESS:
3755 {
3756 14018 ret = read_array(KeyPress, ri->d[rINDEX]/10000) * 10000;
3757 14018 break;
3758 }
3759
3760 case KEYMODIFIERS:
3761 {
3762 ret = (key_shifts*10000);
3763 break;
3764 }
3765
3766 case KEYBINDINGS:
3767 {
3768 int32_t keyid = ri->d[rINDEX]/10000;
3769 switch(keyid)
3770 {
3771 case 0: ret = DUkey * 10000; break;
3772 case 1: ret = DDkey * 10000; break;
3773 case 2: ret = DLkey * 10000; break;
3774 case 3: ret = DRkey * 10000; break;
3775 case 4: ret = Akey * 10000; break;
3776 case 5: ret = Bkey * 10000; break;
3777 case 6: ret = Skey * 10000; break;
3778 case 7: ret = Lkey * 10000; break;
3779 case 8: ret = Rkey * 10000; break;
3780 case 9: ret = Pkey * 10000; /*map*/ break;
3781 case 10: ret = Exkey1 * 10000; break;
3782 case 11: ret = Exkey2 * 10000; break;
3783 case 12: ret = Exkey3 * 10000; break;
3784 case 13: ret = Exkey4 * 10000; break;
3785
3786 default: { Z_scripterrlog("Invalid index [%d] passed to Input->KeyBindings[]\n", keyid); ret = 0; break; }
3787 }
3788 break;
3789 }
3790
3791 case READKEY:
3792 {
3793 //Game->ReadKey(int32_t key), also clears it.
3794 int32_t keyid = ri->d[rINDEX]/10000;
3795 bool pressed = zc_readkey(keyid, true);
3796 ret = pressed?10000:0;
3797 }
3798 break;
3799
3800 case DISABLEKEY:
3801 {
3802 //Input->DisableKey(int32_t key)
3803 ret = read_array(disabledKeys, ri->d[rINDEX]/10000) * 10000;
3804 break;
3805 }
3806
3807 case DISABLEBUTTON:
3808 {
3809 //Input->DisableButton(int32_t cb)
3810 ret = read_array(disable_control, ri->d[rINDEX]/10000) * 10000;
3811 break;
3812 }
3813
3814 case JOYPADPRESS:
3815 {
3816 //Checks if a press is from the joypad, not keyboard.
3817 int32_t button = ri->d[rINDEX]/10000;
3818 ret = joybtn(button)?10000:0;
3819 }
3820 break;
3821
3822
3823 case MOUSEARR:
3824 {
3825 3192 int32_t indx = (ri->d[rINDEX]/10000);
3826 int32_t rv;
3827
2/7
✗ Branch 0 not taken.
✓ Branch 1 taken 1596 times.
✓ Branch 2 taken 1596 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
3192 switch (indx)
3828 {
3829 case 0: //MouseX
3830 {
3831 1596 rv=get_mouse_state(0)*10000;
3832 1596 break;
3833 }
3834 case 1: //MouseY
3835 {
3836 1596 int32_t mousequakeoffset = 56+((int32_t)(zc::math::Sin((double)(quakeclk*int64_t(2)-frame))*4));
3837
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1596 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1596 times.
1596 int32_t tempoffset = (quakeclk > 0) ? mousequakeoffset : (get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset);
3838 1596 int32_t topOffset= (112-tempoffset);
3839 1596 rv=(get_mouse_state(1)-topOffset)*10000;
3840 1596 break;
3841 }
3842 case 2: //MouseZ
3843 {
3844 rv=(get_mouse_state(2))*10000;
3845 break;
3846 }
3847 case 3: //Left Click
3848 {
3849 rv=((get_mouse_state(3)&0x1))*10000;
3850 break;
3851 }
3852 case 4: //Right Click
3853 {
3854 rv=((get_mouse_state(3)&0x2))*10000;
3855 break;
3856 }
3857 case 5: //Middle Click
3858 {
3859 rv=((get_mouse_state(3)&0x4))*10000;
3860 break;
3861 }
3862 default:
3863 {
3864 scripting_log_error_with_context("Invalid index: {}", indx);
3865 rv = -10000;
3866 break;
3867 }
3868 }
3869
3870 //bool pressed = key[keyid] != 0;
3871 //ret = pressed?10000:0;
3872 3192 ret = rv;
3873 }
3874 3192 break;
3875
3876 ///----------------------------------------------------------------------------------------------------//
3877 //Itemdata Variables
3878
3879
3880 case IDATAUSEWPN:
3881 if(unsigned(ri->idata) >= MAXITEMS)
3882 {
3883 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
3884 ret = -10000;
3885 break;
3886 }
3887 ret=(itemsbuf[ri->idata].useweapon)*10000;
3888 break;
3889 case IDATAUSEDEF:
3890 if(unsigned(ri->idata) >= MAXITEMS)
3891 {
3892 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
3893 ret = -10000;
3894 break;
3895 }
3896 ret=(itemsbuf[ri->idata].usedefence)*10000;
3897 break;
3898 case IDATAWRANGE:
3899 if(unsigned(ri->idata) >= MAXITEMS)
3900 {
3901 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
3902 ret = -10000;
3903 break;
3904 }
3905 ret=(itemsbuf[ri->idata].weaprange)*10000;
3906 break;
3907 case IDATAMAGICTIMER:
3908 if(unsigned(ri->idata) >= MAXITEMS)
3909 {
3910 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
3911 ret = -10000;
3912 break;
3913 }
3914 ret=(itemsbuf[ri->idata].magiccosttimer[0])*10000;
3915 break;
3916 case IDATAMAGICTIMER2:
3917 if(unsigned(ri->idata) >= MAXITEMS)
3918 {
3919 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
3920 ret = -10000;
3921 break;
3922 }
3923 ret=(itemsbuf[ri->idata].magiccosttimer[1])*10000;
3924 break;
3925 case IDATAUSEMVT:
3926 {
3927 if(unsigned(ri->idata) >= MAXITEMS)
3928 {
3929 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
3930 ret = -10000;
3931 break;
3932 }
3933 int32_t a = vbound((ri->d[rINDEX] / 10000),0,(ITEM_MOVEMENT_PATTERNS-1));
3934 ret=(itemsbuf[ri->idata].weap_pattern[a])*10000;
3935 }
3936 break;
3937
3938 case IDATADURATION:
3939 if(unsigned(ri->idata) >= MAXITEMS)
3940 {
3941 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
3942 ret = -10000;
3943 break;
3944 }
3945 ret=(itemsbuf[ri->idata].weapduration)*10000;
3946 break;
3947
3948 case IDATADUPLICATES:
3949 if(unsigned(ri->idata) >= MAXITEMS)
3950 {
3951 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
3952 ret = -10000;
3953 break;
3954 }
3955 ret=(itemsbuf[ri->idata].duplicates)*10000;
3956 break;
3957 case IDATADRAWLAYER:
3958 if(unsigned(ri->idata) >= MAXITEMS)
3959 {
3960 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
3961 ret = -10000;
3962 break;
3963 }
3964 ret=(itemsbuf[ri->idata].drawlayer)*10000;
3965 break;
3966 case IDATACOLLECTFLAGS:
3967 if(unsigned(ri->idata) >= MAXITEMS)
3968 {
3969 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
3970 ret = 0;
3971 break;
3972 }
3973 ret=(itemsbuf[ri->idata].collectflags)*10000;
3974 break;
3975 case IDATAWEAPONSCRIPT:
3976 if(unsigned(ri->idata) >= MAXITEMS)
3977 {
3978 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
3979 ret = -10000;
3980 break;
3981 }
3982 ret=(itemsbuf[ri->idata].weaponscript)*10000;
3983 break;
3984 case IDATAMISCD:
3985 {
3986 if(unsigned(ri->idata) >= MAXITEMS)
3987 {
3988 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
3989 ret = -10000;
3990 break;
3991 }
3992 int32_t a = vbound((ri->d[rINDEX] / 10000),0,31);
3993 ret=(itemsbuf[ri->idata].wpn_misc_d[a])*10000;
3994 }
3995 break;
3996 case IDATAWPNINITD:
3997 {
3998 if(unsigned(ri->idata) >= MAXITEMS)
3999 {
4000 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4001 ret = -10000;
4002 break;
4003 }
4004 int32_t a = vbound((ri->d[rINDEX] / 10000),0,7);
4005 ret=(itemsbuf[ri->idata].weap_initiald[a]);
4006 }
4007 break;
4008 case IDATAWEAPHXOFS:
4009 if(unsigned(ri->idata) >= MAXITEMS)
4010 {
4011 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4012 ret = -10000;
4013 break;
4014 }
4015 ret=(itemsbuf[ri->idata].weap_hxofs)*10000;
4016 break;
4017 case IDATAWEAPHYOFS:
4018 if(unsigned(ri->idata) >= MAXITEMS)
4019 {
4020 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4021 ret = -10000;
4022 break;
4023 }
4024 ret=(itemsbuf[ri->idata].weap_hyofs)*10000;
4025 break;
4026 case IDATAWEAPHXSZ:
4027 if(unsigned(ri->idata) >= MAXITEMS)
4028 {
4029 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4030 ret = -10000;
4031 break;
4032 }
4033 ret=(itemsbuf[ri->idata].weap_hxsz)*10000;
4034 break;
4035 case IDATAWEAPHYSZ:
4036 if(unsigned(ri->idata) >= MAXITEMS)
4037 {
4038 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4039 ret = -10000;
4040 break;
4041 }
4042 ret=(itemsbuf[ri->idata].weap_hysz)*10000;
4043 break;
4044 case IDATAWEAPHZSZ:
4045 if(unsigned(ri->idata) >= MAXITEMS)
4046 {
4047 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4048 ret = -10000;
4049 break;
4050 }
4051 ret=(itemsbuf[ri->idata].weap_hzsz)*10000;
4052 break;
4053 case IDATAWEAPXOFS:
4054 if(unsigned(ri->idata) >= MAXITEMS)
4055 {
4056 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4057 ret = -10000;
4058 break;
4059 }
4060 ret=(itemsbuf[ri->idata].weap_xofs)*10000;
4061 break;
4062 case IDATAWEAPYOFS:
4063 if(unsigned(ri->idata) >= MAXITEMS)
4064 {
4065 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4066 ret = -10000;
4067 break;
4068 }
4069 ret=(itemsbuf[ri->idata].weap_yofs)*10000;
4070 break;
4071 case IDATAHXOFS:
4072 if(unsigned(ri->idata) >= MAXITEMS)
4073 {
4074 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4075 ret = -10000;
4076 break;
4077 }
4078 ret=(itemsbuf[ri->idata].hxofs)*10000;
4079 break;
4080 case IDATAHYOFS:
4081 if(unsigned(ri->idata) >= MAXITEMS)
4082 {
4083 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4084 ret = -10000;
4085 break;
4086 }
4087 ret=(itemsbuf[ri->idata].hyofs)*10000;
4088 break;
4089 case IDATAHXSZ:
4090 if(unsigned(ri->idata) >= MAXITEMS)
4091 {
4092 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4093 ret = -10000;
4094 break;
4095 }
4096 ret=(itemsbuf[ri->idata].hxsz)*10000;
4097 break;
4098 case IDATAHYSZ:
4099 if(unsigned(ri->idata) >= MAXITEMS)
4100 {
4101 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4102 ret = -10000;
4103 break;
4104 }
4105 ret=(itemsbuf[ri->idata].hysz)*10000;
4106 break;
4107 case IDATAHZSZ:
4108 if(unsigned(ri->idata) >= MAXITEMS)
4109 {
4110 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4111 ret = -10000;
4112 break;
4113 }
4114 ret=(itemsbuf[ri->idata].hzsz)*10000;
4115 break;
4116 case IDATADXOFS:
4117 if(unsigned(ri->idata) >= MAXITEMS)
4118 {
4119 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4120 ret = -10000;
4121 break;
4122 }
4123 ret=(itemsbuf[ri->idata].xofs)*10000;
4124 break;
4125 case IDATADYOFS:
4126 if(unsigned(ri->idata) >= MAXITEMS)
4127 {
4128 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4129 ret = -10000;
4130 break;
4131 }
4132 ret=(itemsbuf[ri->idata].yofs)*10000;
4133 break;
4134 case IDATATILEW:
4135 if(unsigned(ri->idata) >= MAXITEMS)
4136 {
4137 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4138 ret = -10000;
4139 break;
4140 }
4141 ret=(itemsbuf[ri->idata].tilew)*10000;
4142 break;
4143 case IDATATILEH:
4144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
53 if(unsigned(ri->idata) >= MAXITEMS)
4145 {
4146 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4147 ret = -10000;
4148 break;
4149 }
4150 53 ret=(itemsbuf[ri->idata].tileh)*10000;
4151 53 break;
4152 case IDATAPICKUP:
4153 if(unsigned(ri->idata) >= MAXITEMS)
4154 {
4155 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4156 ret = -10000;
4157 break;
4158 }
4159 ret=(itemsbuf[ri->idata].pickup)*10000;
4160 break;
4161 case IDATAOVERRIDEFL:
4162 if(unsigned(ri->idata) >= MAXITEMS)
4163 {
4164 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4165 ret = 0;
4166 break;
4167 }
4168 ret=(itemsbuf[ri->idata].overrideFLAGS)*10000;
4169 break;
4170
4171 case IDATATILEWWEAP:
4172 if(unsigned(ri->idata) >= MAXITEMS)
4173 {
4174 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4175 ret = -10000;
4176 break;
4177 }
4178 ret=(itemsbuf[ri->idata].weap_tilew)*10000;
4179 break;
4180 case IDATATILEHWEAP:
4181 if(unsigned(ri->idata) >= MAXITEMS)
4182 {
4183 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4184 ret = -10000;
4185 break;
4186 }
4187 ret=(itemsbuf[ri->idata].weap_tileh)*10000;
4188 break;
4189 case IDATAOVERRIDEFLWEAP:
4190 if(unsigned(ri->idata) >= MAXITEMS)
4191 {
4192 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4193 ret = 0;
4194 break;
4195 }
4196 ret=(itemsbuf[ri->idata].weapoverrideFLAGS)*10000;
4197 break;
4198
4199 case IDATAFAMILY:
4200
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5960535 times.
5960535 if(unsigned(ri->idata) >= MAXITEMS)
4201 {
4202 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4203 ret = -10000;
4204 break;
4205 }
4206 5960535 ret=(itemsbuf[ri->idata].family)*10000;
4207 5960535 break;
4208
4209 case IDATALEVEL:
4210
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16858 times.
16858 if(unsigned(ri->idata) >= MAXITEMS)
4211 {
4212 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4213 ret = -10000;
4214 break;
4215 }
4216 16858 ret=(itemsbuf[ri->idata].fam_type)*10000;
4217 16858 break;
4218
4219 case IDATAKEEP:
4220 3 ret = item_flag(item_gamedata);
4221 3 break;
4222
4223 case IDATAAMOUNT:
4224 {
4225 if(unsigned(ri->idata) >= MAXITEMS)
4226 {
4227 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4228 ret = -10000;
4229 break;
4230 }
4231 int32_t v = itemsbuf[ri->idata].amount;
4232 ret = ((v&0x4000)?-1:1)*(v & 0x3FFF)*10000;
4233 break;
4234 }
4235 case IDATAGRADUAL:
4236 {
4237 if(unsigned(ri->idata) >= MAXITEMS)
4238 {
4239 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4240 ret = -10000;
4241 break;
4242 }
4243 ret = (itemsbuf[ri->idata].amount&0x8000) ? 10000 : 0;
4244 break;
4245 }
4246 case IDATACONSTSCRIPT:
4247 ret = item_flag(item_passive_script);
4248 break;
4249 case IDATASSWIMDISABLED:
4250 ret = item_flag(item_sideswim_disabled);
4251 break;
4252 case IDATABUNNYABLE:
4253 ret = item_flag(item_bunny_enabled);
4254 break;
4255 case IDATAJINXIMMUNE:
4256 ret = item_flag(item_jinx_immune);
4257 break;
4258 case IDATAJINXSWAP:
4259 ret = item_flag(item_flip_jinx);
4260 break;
4261 case IDATAUSEBURNSPR:
4262 ret = item_flag(item_burning_sprites);
4263 break;
4264
4265 case IDATASETMAX:
4266 if(unsigned(ri->idata) >= MAXITEMS)
4267 {
4268 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4269 ret = -10000;
4270 break;
4271 }
4272 ret=(itemsbuf[ri->idata].setmax)*10000;
4273 break;
4274
4275 case IDATAMAX:
4276 if(unsigned(ri->idata) >= MAXITEMS)
4277 {
4278 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4279 ret = -10000;
4280 break;
4281 }
4282 ret=(itemsbuf[ri->idata].max)*10000;
4283 break;
4284
4285 case IDATACOUNTER:
4286 if(unsigned(ri->idata) >= MAXITEMS)
4287 {
4288 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4289 ret = -10000;
4290 break;
4291 }
4292 ret=(itemsbuf[ri->idata].count)*10000;
4293 break;
4294
4295 case IDATAPSOUND:
4296 if(unsigned(ri->idata) >= MAXITEMS)
4297 {
4298 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4299 ret = -10000;
4300 break;
4301 }
4302 ret=(itemsbuf[ri->idata].playsound)*10000;
4303 break;
4304 case IDATAUSESOUND:
4305 if(unsigned(ri->idata) >= MAXITEMS)
4306 {
4307 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4308 ret = -10000;
4309 break;
4310 }
4311 ret=(itemsbuf[ri->idata].usesound)*10000;
4312 break;
4313
4314 case IDATAUSESOUND2:
4315 if(unsigned(ri->idata) >= MAXITEMS)
4316 {
4317 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4318 ret = -10000;
4319 break;
4320 }
4321 ret=(itemsbuf[ri->idata].usesound2)*10000;
4322 break;
4323
4324 case IDATAPOWER:
4325
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1994 times.
1994 if(unsigned(ri->idata) >= MAXITEMS)
4326 {
4327 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4328 ret = -10000;
4329 break;
4330 }
4331 1994 ret=(itemsbuf[ri->idata].power)*10000;
4332 1994 break;
4333
4334 //Get the ID of an item.
4335 case IDATAID:
4336
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1914 times.
1914 if(unsigned(ri->idata) >= MAXITEMS)
4337 {
4338 //Don't error here //scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4339 ret = -10000;
4340 break;
4341 }
4342 1914 ret=ri->idata*10000;
4343 1914 break;
4344
4345 //Get the script assigned to an item (active)
4346 case IDATASCRIPT:
4347 if(unsigned(ri->idata) >= MAXITEMS)
4348 {
4349 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4350 ret = -10000;
4351 break;
4352 }
4353 ret=(itemsbuf[ri->idata].script)*10000;
4354 break;
4355 case IDATASPRSCRIPT:
4356 if(unsigned(ri->idata) >= MAXITEMS)
4357 {
4358 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4359 ret = -10000;
4360 break;
4361 }
4362 ret=(itemsbuf[ri->idata].sprite_script)*10000;
4363 break;
4364 //Get the ->Attributes[] of an item
4365 case IDATAATTRIB:
4366 case IDATAATTRIB_L:
4367 {
4368 154 int vscale = (arg==IDATAATTRIB_L)?1:10000;
4369
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 154 times.
154 if(unsigned(ri->idata) >= MAXITEMS)
4370 {
4371 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4372 ret = -1*vscale;
4373 break;
4374 }
4375 154 int32_t index = vbound(ri->d[rINDEX]/10000,0,9);
4376
2/11
✗ Branch 0 not taken.
✓ Branch 1 taken 94 times.
✓ Branch 2 taken 60 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
154 switch(index)
4377 {
4378 case 0:
4379 94 ret=(itemsbuf[ri->idata].misc1); break;
4380 case 1:
4381 60 ret=(itemsbuf[ri->idata].misc2); break;
4382 case 2:
4383 ret=(itemsbuf[ri->idata].misc3); break;
4384 case 3:
4385 ret=(itemsbuf[ri->idata].misc4); break;
4386 case 4:
4387 ret=(itemsbuf[ri->idata].misc5); break;
4388 case 5:
4389 ret=(itemsbuf[ri->idata].misc6); break;
4390 case 6:
4391 ret=(itemsbuf[ri->idata].misc7); break;
4392 case 7:
4393 ret=(itemsbuf[ri->idata].misc8); break;
4394 case 8:
4395 ret=(itemsbuf[ri->idata].misc9); break;
4396 case 9:
4397 ret=(itemsbuf[ri->idata].misc10); break;
4398 default:
4399 ret = -1; break;
4400 }
4401 154 ret *= vscale;
4402 154 break;
4403 }
4404 //Get the ->Sprite[] of an item.
4405 case IDATASPRITE:
4406 {
4407 if(unsigned(ri->idata) >= MAXITEMS)
4408 {
4409 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4410 ret = -10000;
4411 break;
4412 }
4413 int32_t index = ri->d[rINDEX]/10000;
4414 switch(index)
4415 {
4416 case 0:
4417 ret=(itemsbuf[ri->idata].wpn)*10000; break;
4418 case 1:
4419 ret=(itemsbuf[ri->idata].wpn2)*10000; break;
4420 case 2:
4421 ret=(itemsbuf[ri->idata].wpn3)*10000; break;
4422 case 3:
4423 ret=(itemsbuf[ri->idata].wpn4)*10000; break;
4424 case 4:
4425 ret=(itemsbuf[ri->idata].wpn5)*10000; break;
4426 case 5:
4427 ret=(itemsbuf[ri->idata].wpn6)*10000; break;
4428 case 6:
4429 ret=(itemsbuf[ri->idata].wpn7)*10000; break;
4430 case 7:
4431 ret=(itemsbuf[ri->idata].wpn8)*10000; break;
4432 case 8:
4433 ret=(itemsbuf[ri->idata].wpn9)*10000; break;
4434 case 9:
4435 ret=(itemsbuf[ri->idata].wpn10)*10000; break;
4436 default:
4437 scripting_log_error_with_context("Invalid index: {}", index);
4438 ret = -10000;
4439 break;
4440 }
4441 break;
4442 }
4443 case IDATABURNINGSPR:
4444 {
4445 if(unsigned(ri->idata) >= MAXITEMS)
4446 {
4447 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4448 ret = -10000;
4449 break;
4450 }
4451 int32_t index = ri->d[rINDEX]/10000;
4452 if(index < 0 || index >= WPNSPR_MAX)
4453 {
4454 scripting_log_error_with_context("Invalid index: {}", index);
4455 ret = -10000;
4456 break;
4457 }
4458 ret = itemsbuf[ri->idata].burnsprs[index]*10000;
4459 break;
4460 }
4461 case IDATABURNINGLIGHTRAD:
4462 {
4463 if(unsigned(ri->idata) >= MAXITEMS)
4464 {
4465 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4466 ret = -10000;
4467 break;
4468 }
4469 int32_t index = ri->d[rINDEX]/10000;
4470 if(index < 0 || index >= WPNSPR_MAX)
4471 {
4472 scripting_log_error_with_context("Invalid index: {}", index);
4473 ret = -10000;
4474 break;
4475 }
4476 ret = itemsbuf[ri->idata].light_rads[index]*10000;
4477 break;
4478 }
4479 //Hero TIle modifier
4480 case IDATALTM:
4481 if(unsigned(ri->idata) >= MAXITEMS)
4482 {
4483 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4484 ret = 0;
4485 break;
4486 }
4487 ret=(itemsbuf[ri->idata].ltm)*10000;
4488 break;
4489 //Pickup script
4490 case IDATAPSCRIPT:
4491 if(unsigned(ri->idata) >= MAXITEMS)
4492 {
4493 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4494 ret = -10000;
4495 break;
4496 }
4497 ret=(itemsbuf[ri->idata].collect_script)*10000;
4498 break;
4499 //Pickup string
4500 case IDATAPSTRING:
4501 if(unsigned(ri->idata) >= MAXITEMS)
4502 {
4503 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4504 ret = -10000;
4505 break;
4506 }
4507 ret=(itemsbuf[ri->idata].pstring)*10000;
4508 break;
4509 case IDATAPFLAGS:
4510 if(unsigned(ri->idata) >= MAXITEMS)
4511 {
4512 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4513 ret = 0;
4514 break;
4515 }
4516 ret=(itemsbuf[ri->idata].pickup_string_flags)*10000;
4517 break;
4518 //Magic cost
4519 case IDATAMAGCOST:
4520 if(unsigned(ri->idata) >= MAXITEMS)
4521 {
4522 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4523 ret = -10000;
4524 break;
4525 }
4526 ret=(itemsbuf[ri->idata].cost_amount[0])*10000;
4527 break;
4528 case IDATACOST2:
4529 if(unsigned(ri->idata) >= MAXITEMS)
4530 {
4531 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4532 ret = -10000;
4533 break;
4534 }
4535 ret=(itemsbuf[ri->idata].cost_amount[1])*10000;
4536 break;
4537 //cost counter ref
4538 case IDATACOSTCOUNTER:
4539 if(unsigned(ri->idata) >= MAXITEMS)
4540 {
4541 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4542 ret = -10000;
4543 break;
4544 }
4545 ret=(itemsbuf[ri->idata].cost_counter[0])*10000;
4546 break;
4547 case IDATACOSTCOUNTER2:
4548 if(unsigned(ri->idata) >= MAXITEMS)
4549 {
4550 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4551 ret = -10000;
4552 break;
4553 }
4554 ret=(itemsbuf[ri->idata].cost_counter[1])*10000;
4555 break;
4556 //Min Hearts to Pick Up
4557 case IDATAMINHEARTS:
4558 if(unsigned(ri->idata) >= MAXITEMS)
4559 {
4560 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4561 ret = -10000;
4562 break;
4563 }
4564 ret=(itemsbuf[ri->idata].pickup_hearts)*10000;
4565 break;
4566 //Tile used by the item
4567 case IDATATILE:
4568
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55670 times.
55670 if(unsigned(ri->idata) >= MAXITEMS)
4569 {
4570 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4571 ret = -10000;
4572 break;
4573 }
4574 55670 ret=(itemsbuf[ri->idata].tile)*10000;
4575 55670 break;
4576 //itemdata->Flash
4577 case IDATAMISC:
4578 if(unsigned(ri->idata) >= MAXITEMS)
4579 {
4580 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4581 ret = -10000;
4582 break;
4583 }
4584 ret=(itemsbuf[ri->idata].misc_flags)*10000;
4585 break;
4586 //->CSet
4587 case IDATACSET:
4588
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55645 times.
55645 if(unsigned(ri->idata) >= MAXITEMS)
4589 {
4590 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4591 ret = -10000;
4592 break;
4593 }
4594
4595 55645 ret = (itemsbuf[ri->idata].csets&15)*10000;
4596
4597 // If we find quests that broke, use this code.
4598 // if (QHeader.compareVer(2, 55, 9) >= 0)
4599 // ret = (itemsbuf[ri->idata].csets&15)*10000;
4600 // else
4601 // ret = itemsbuf[ri->idata].csets*10000;
4602 55645 break;
4603 case IDATAFLASHCSET:
4604 if(unsigned(ri->idata) >= MAXITEMS)
4605 {
4606 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4607 ret = -10000;
4608 break;
4609 }
4610 ret=(itemsbuf[ri->idata].csets>>4)*10000;
4611 break;
4612 //->A.Frames
4613 case IDATAFRAMES:
4614
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 63041 times.
63041 if(unsigned(ri->idata) >= MAXITEMS)
4615 {
4616 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4617 ret = -10000;
4618 break;
4619 }
4620 63041 ret=(itemsbuf[ri->idata].frames)*10000;
4621 63041 break;
4622 /*
4623 case IDATAFRAME:
4624 ret=(itemsbuf[ri->idata].frame)*10000;
4625 break;
4626 */
4627 //->A.Speed
4628 case IDATAASPEED:
4629
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 142873 times.
142873 if(unsigned(ri->idata) >= MAXITEMS)
4630 {
4631 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4632 ret = -10000;
4633 break;
4634 }
4635 142873 ret=(itemsbuf[ri->idata].speed)*10000;
4636 142873 break;
4637 //->Delay
4638 case IDATADELAY:
4639
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 74538 times.
74538 if(unsigned(ri->idata) >= MAXITEMS)
4640 {
4641 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4642 ret = -10000;
4643 break;
4644 }
4645 74538 ret=(itemsbuf[ri->idata].delay)*10000;
4646 74538 break;
4647 // teo of this item upgrades
4648 case IDATACOMBINE:
4649 ret = item_flag(item_combine);
4650 break;
4651 //Use item, and get the lower level one
4652 case IDATADOWNGRADE:
4653 ret = item_flag(item_downgrade);
4654 break;
4655 //Only validate the cost, don't charge it
4656 case IDATAVALIDATE:
4657 ret = item_flag(item_validate_only);
4658 break;
4659 case IDATAVALIDATE2:
4660 ret = item_flag(item_validate_only_2);
4661 break;
4662 //->Flags[5]
4663 case IDATAFLAGS:
4664 {
4665 if(unsigned(ri->idata) >= MAXITEMS)
4666 {
4667 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4668 ret = 0;
4669 break;
4670 }
4671 int32_t index = ri->d[rINDEX]/10000;
4672 switch(index)
4673 {
4674 case 0:
4675 ret=(itemsbuf[ri->idata].flags & item_flag1)?10000:0; break;
4676 case 1:
4677 ret=(itemsbuf[ri->idata].flags & item_flag2)?10000:0; break;
4678 case 2:
4679 ret=(itemsbuf[ri->idata].flags & item_flag3)?10000:0; break;
4680 case 3:
4681 ret=(itemsbuf[ri->idata].flags & item_flag4)?10000:0; break;
4682 case 4:
4683 ret=(itemsbuf[ri->idata].flags & item_flag5)?10000:0; break;
4684 case 5:
4685 ret=(itemsbuf[ri->idata].flags & item_flag6)?10000:0; break;
4686 case 6:
4687 ret=(itemsbuf[ri->idata].flags & item_flag7)?10000:0; break;
4688 case 7:
4689 ret=(itemsbuf[ri->idata].flags & item_flag8)?10000:0; break;
4690 case 8:
4691 ret=(itemsbuf[ri->idata].flags & item_flag9)?10000:0; break;
4692 case 9:
4693 ret=(itemsbuf[ri->idata].flags & item_flag10)?10000:0; break;
4694 case 10:
4695 ret=(itemsbuf[ri->idata].flags & item_flag11)?10000:0; break;
4696 case 11:
4697 ret=(itemsbuf[ri->idata].flags & item_flag12)?10000:0; break;
4698 case 12:
4699 ret=(itemsbuf[ri->idata].flags & item_flag13)?10000:0; break;
4700 case 13:
4701 ret=(itemsbuf[ri->idata].flags & item_flag14)?10000:0; break;
4702 case 14:
4703 ret=(itemsbuf[ri->idata].flags & item_flag15)?10000:0; break;
4704 case 15:
4705 ret=(itemsbuf[ri->idata].flags & item_passive_script)?10000:0; break;
4706
4707
4708 default:
4709 Z_scripterrlog("Invalid itemdata->Flags[] index: %d\n", index);
4710 ret = 0;
4711 break;
4712 }
4713 break;
4714 }
4715
4716 //->Keep Old
4717 case IDATAKEEPOLD:
4718 ret = item_flag(item_keep_old);
4719 break;
4720 //Use rupees instead of magic
4721 case IDATARUPEECOST:
4722 ret = item_flag(item_rupee_magic);
4723 break;
4724 //Can be eaten
4725 case IDATAEDIBLE:
4726 ret = item_flag(item_edible);
4727 break;
4728 //currently unused
4729 case IDATAFLAGUNUSED:
4730 ret = item_flag(item_unused);
4731 break;
4732 //Gain lower level items when collected
4733 case IDATAGAINLOWER:
4734 ret = item_flag(item_gain_old);
4735 break;
4736 //Unchanged from master
4737 case IDATAINITDD:
4738 {
4739 int32_t a = ri->d[rINDEX] / 10000;
4740 if(unsigned(ri->idata) >= MAXITEMS)
4741 {
4742 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4743 ret = -10000;
4744 break;
4745 }
4746
4747 if(BC::checkBounds(a, 0, 7) != SH::_NoError)
4748 ret = -10000;
4749 else
4750 ret = itemsbuf[ri->idata].initiald[a];
4751 }
4752 break;
4753
4754 ///----------------------------------------------------------------------------------------------------//
4755 //LWeapon Variables
4756 case LWPNSPECIAL:
4757 if(0!=(s=checkLWpn(ri->lwpn)))
4758 ret=((int32_t)((weapon*)(s))->specialinfo)*10000;
4759
4760
4761 break;
4762
4763 case LWPNSCALE:
4764 if ( get_qr(qr_OLDSPRITEDRAWS) )
4765 {
4766 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
4767 ret = -1; break;
4768 }
4769 if(0!=(s=checkLWpn(ri->lwpn)))
4770 ret=((int32_t)((weapon*)(s))->scale)*100.0;
4771
4772 break;
4773
4774 case LWPNX:
4775
2/2
✓ Branch 0 taken 15492 times.
✓ Branch 1 taken 939265 times.
954757 if(0!=(s=checkLWpn(ri->lwpn)))
4776 {
4777
2/2
✓ Branch 0 taken 350528 times.
✓ Branch 1 taken 588737 times.
939265 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
4778 {
4779 350528 ret=(((weapon*)(s))->x).getZLong();
4780 350528 }
4781 else
4782 588737 ret=((int32_t)((weapon*)(s))->x)*10000;
4783 939265 }
4784
4785 954757 break;
4786
4787 case SPRITEMAXLWPN:
4788 {
4789 //No bounds check, as this is a universal function and works from NULL pointers!
4790 ret = Lwpns.getMax() * 10000;
4791 break;
4792 }
4793
4794 case LWPNY:
4795
2/2
✓ Branch 0 taken 15492 times.
✓ Branch 1 taken 934658 times.
950150 if(0!=(s=checkLWpn(ri->lwpn)))
4796 {
4797
2/2
✓ Branch 0 taken 350395 times.
✓ Branch 1 taken 584263 times.
934658 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
4798 {
4799 350395 ret=(((weapon*)(s))->y).getZLong();
4800 350395 }
4801 else
4802 584263 ret=((int32_t)((weapon*)(s))->y)*10000;
4803 934658 }
4804 950150 break;
4805
4806 case LWPNZ:
4807
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 109736 times.
109736 if(0!=(s=checkLWpn(ri->lwpn)))
4808 {
4809
2/2
✓ Branch 0 taken 53984 times.
✓ Branch 1 taken 55752 times.
109736 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
4810 {
4811 53984 ret=(((weapon*)(s))->z).getZLong();
4812 53984 }
4813 else
4814 55752 ret=((int32_t)((weapon*)(s))->z)*10000;
4815 109736 }
4816
4817 109736 break;
4818
4819 case LWPNJUMP:
4820
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
4821 {
4822 6 ret = ((weapon*)(s))->fall.getZLong() / -100;
4823
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (get_qr(qr_SPRITE_JUMP_IS_TRUNCATED)) ret = trunc(ret / 10000) * 10000;
4824 6 }
4825
4826 6 break;
4827
4828 case LWPNFAKEJUMP:
4829 if(0!=(s=checkLWpn(ri->lwpn)))
4830 {
4831 ret = ((weapon*)(s))->fakefall.getZLong() / -100;
4832 if (get_qr(qr_SPRITE_JUMP_IS_TRUNCATED)) ret = trunc(ret / 10000) * 10000;
4833 }
4834
4835 break;
4836
4837 case LWPNDIR:
4838
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80933 times.
80933 if(0!=(s=checkLWpn(ri->lwpn)))
4839 80933 ret=((weapon*)(s))->dir*10000;
4840
4841 80933 break;
4842
4843 case LWPNGRAVITY:
4844 if(0!=(s=checkLWpn(ri->lwpn)))
4845 ret= (((weapon*)(s))->moveflags & move_obeys_grav) ? 10000 : 0;
4846
4847 break;
4848
4849 case LWPNSTEP:
4850
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5388 times.
5388 if(0!=(s=checkLWpn(ri->lwpn)))
4851 {
4852
3/4
✓ Branch 0 taken 1140 times.
✓ Branch 1 taken 4248 times.
✓ Branch 2 taken 1140 times.
✗ Branch 3 not taken.
5388 if ( get_qr(qr_STEP_IS_FLOAT) || replay_is_active() )
4853 {
4854 5388 ret=((weapon*)s)->step.getZLong() * 100;
4855 5388 }
4856 //old, buggy code replication, round two: Go! -Z
4857 //else ret = ( ( ( ((weapon*)s)->step ) * 100.0 ).getZLong() );
4858
4859 //else
4860 //{
4861 //old, buggy code replication, round THREE: Go! -Z
4862 // double tmp = ( ((weapon*)s)->step.getFloat() ) * 1000000.0;
4863 // ret = (int32_t)tmp;
4864 //}
4865
4866 //old, buggy code replication, round FOUR: Go! -Z
4867 else ret = (int32_t)((float)((weapon*)s)->step * 1000000.0);
4868 5388 }
4869 5388 break;
4870
4871 case LWPNANGLE:
4872
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 416 times.
416 if(0!=(s=checkLWpn(ri->lwpn)))
4873 416 ret=(int32_t)(((weapon*)(s))->angle*10000);
4874
4875 416 break;
4876
4877 case LWPNDEGANGLE:
4878 if(0!=(s=checkLWpn(ri->lwpn)))
4879 {
4880 ret=(int32_t)(((weapon*)(s))->angle*(180.0 / PI)*10000);
4881 }
4882
4883 break;
4884
4885 case LWPNVX:
4886
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 246 times.
246 if(0!=(s=checkLWpn(ri->lwpn)))
4887 {
4888
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 246 times.
246 if (((weapon*)(s))->angular)
4889 ret = int32_t(zc::math::Cos(((weapon*)s)->angle)*10000.0*((weapon*)s)->step);
4890 else
4891 {
4892
4/7
✓ Branch 0 taken 246 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 246 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 122 times.
✓ Branch 6 taken 124 times.
246 switch(NORMAL_DIR(((weapon*)(s))->dir))
4893 {
4894 case l_up:
4895 case l_down:
4896 case left:
4897 ret = int32_t(-10000.0*((weapon*)s)->step);
4898 break;
4899
4900 case r_down:
4901 case r_up:
4902 case right:
4903 122 ret = int32_t(10000.0*((weapon*)s)->step);
4904 122 break;
4905
4906 default:
4907 124 ret = 0;
4908 124 break;
4909 }
4910 }
4911 246 }
4912
4913 246 break;
4914
4915 case LWPNVY:
4916 if(0!=(s=checkLWpn(ri->lwpn)))
4917 {
4918 if (((weapon*)(s))->angular)
4919 ret = int32_t(zc::math::Sin(((weapon*)s)->angle)*10000.0*((weapon*)s)->step);
4920 else
4921 {
4922 switch(NORMAL_DIR(((weapon*)(s))->dir))
4923 {
4924 case l_up:
4925 case r_up:
4926 case up:
4927 ret = int32_t(-10000.0*((weapon*)s)->step);
4928 break;
4929 case l_down:
4930 case r_down:
4931 case down:
4932 ret = int32_t(10000.0*((weapon*)s)->step);
4933 break;
4934
4935 default:
4936 ret = 0;
4937 break;
4938 }
4939 }
4940 }
4941
4942 break;
4943
4944 case LWPNANGULAR:
4945
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(0!=(s=checkLWpn(ri->lwpn)))
4946 6 ret=((weapon*)(s))->angular*10000;
4947
4948 6 break;
4949
4950 case LWPNAUTOROTATE:
4951 if(0!=(s=checkLWpn(ri->lwpn)))
4952 ret=((weapon*)(s))->autorotate*10000;
4953
4954 break;
4955
4956 case LWPNBEHIND:
4957 if(0!=(s=checkLWpn(ri->lwpn)))
4958 ret=((weapon*)(s))->behind*10000;
4959
4960 break;
4961
4962 case LWPNDRAWTYPE:
4963
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(0!=(s=checkLWpn(ri->lwpn)))
4964 6 ret=((weapon*)(s))->drawstyle*10000;
4965
4966 6 break;
4967
4968 case LWPNPOWER:
4969
2/2
✓ Branch 0 taken 103895 times.
✓ Branch 1 taken 1 times.
103896 if(0!=(s=checkLWpn(ri->lwpn)))
4970 103895 ret=((weapon*)(s))->power*10000;
4971
4972 103896 break;
4973 /*
4974 case LWPNRANGE:
4975 if(0!=(s=checkLWpn(ri->lwpn)))
4976 ret=((weapon*)(s))->scriptrange*10000;
4977
4978 break;
4979 */
4980 case LWPNDEAD:
4981
1/2
✓ Branch 0 taken 7611 times.
✗ Branch 1 not taken.
7611 if(0!=(s=checkLWpn(ri->lwpn)))
4982 7611 ret=((weapon*)(s))->dead*10000;
4983
4984 7611 break;
4985
4986 case LWPNID:
4987
2/2
✓ Branch 0 taken 4092488 times.
✓ Branch 1 taken 16620 times.
4109108 if(0!=(s=checkLWpn(ri->lwpn)))
4988 4092488 ret=((weapon*)(s))->id*10000;
4989
4990 4109108 break;
4991
4992 case LWPNTILE:
4993
1/2
✓ Branch 0 taken 53697 times.
✗ Branch 1 not taken.
53697 if(0!=(s=checkLWpn(ri->lwpn)))
4994 53697 ret=((weapon*)(s))->tile*10000;
4995
4996 53697 break;
4997
4998 case LWPNSCRIPTTILE:
4999
1/2
✓ Branch 0 taken 586 times.
✗ Branch 1 not taken.
586 if(0!=(s=checkLWpn(ri->lwpn)))
5000 586 ret=((weapon*)(s))->scripttile*10000;
5001
5002 586 break;
5003
5004 case LWPNSCRIPTFLIP:
5005 if(0!=(s=checkLWpn(ri->lwpn)))
5006 ret=((weapon*)(s))->scriptflip*10000;
5007
5008 break;
5009
5010 case LWPNCSET:
5011
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53381 times.
53381 if(0!=(s=checkLWpn(ri->lwpn)))
5012 53381 ret=((weapon*)(s))->cs*10000;
5013
5014 53381 break;
5015
5016 case LWPNFLASHCSET:
5017
1/2
✓ Branch 0 taken 220 times.
✗ Branch 1 not taken.
220 if(0!=(s=checkLWpn(ri->lwpn)))
5018 220 ret=(((weapon*)(s))->o_cset>>4)*10000;
5019
5020 220 break;
5021
5022 case LWPNFRAMES:
5023
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4362 times.
4362 if(0!=(s=checkLWpn(ri->lwpn)))
5024 4362 ret=((weapon*)(s))->frames*10000;
5025
5026 4362 break;
5027
5028 case LWPNFRAME:
5029
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(0!=(s=checkLWpn(ri->lwpn)))
5030 6 ret=((weapon*)(s))->aframe*10000;
5031
5032 6 break;
5033
5034 case LWPNASPEED:
5035
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4362 times.
4362 if(0!=(s=checkLWpn(ri->lwpn)))
5036 4362 ret=((weapon*)(s))->o_speed*10000;
5037
5038 4362 break;
5039
5040 case LWPNFLASH:
5041
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
5042 6 ret=((weapon*)(s))->flash*10000;
5043
5044 6 break;
5045
5046 case LWPNFLIP:
5047 if(0!=(s=checkLWpn(ri->lwpn)))
5048 ret=((weapon*)(s))->flip*10000;
5049
5050 break;
5051
5052 case LWPNCOUNT:
5053 1950927 ret=Lwpns.Count()*10000;
5054 1950927 break;
5055
5056 case LWPNEXTEND:
5057
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(0!=(s=checkLWpn(ri->lwpn)))
5058 6 ret=((weapon*)(s))->extend*10000;
5059
5060 6 break;
5061
5062 case LWPNOTILE:
5063
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 835937 times.
835937 if(0!=(s=checkLWpn(ri->lwpn)))
5064 835937 ret=((weapon*)(s))->o_tile*10000;
5065
5066 835937 break;
5067
5068 case LWPNOCSET:
5069
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23909 times.
23909 if(0!=(s=checkLWpn(ri->lwpn)))
5070 23909 ret=(((weapon*)(s))->o_cset&15)*10000;
5071
5072 23909 break;
5073
5074 case LWPNHXOFS:
5075
2/2
✓ Branch 0 taken 15492 times.
✓ Branch 1 taken 284226 times.
299718 if(0!=(s=checkLWpn(ri->lwpn)))
5076 284226 ret=(((weapon*)(s))->hxofs)*10000;
5077
5078 299718 break;
5079
5080 case LWPNHYOFS:
5081
2/2
✓ Branch 0 taken 281478 times.
✓ Branch 1 taken 15492 times.
296970 if(0!=(s=checkLWpn(ri->lwpn)))
5082 281478 ret=(((weapon*)(s))->hyofs)*10000;
5083
5084 296970 break;
5085
5086 case LWPNXOFS:
5087
1/2
✓ Branch 0 taken 10231 times.
✗ Branch 1 not taken.
10231 if(0!=(s=checkLWpn(ri->lwpn)))
5088 10231 ret=((int32_t)(((weapon*)(s))->xofs))*10000;
5089
5090 10231 break;
5091
5092 case LWPNYOFS:
5093
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11477 times.
11477 if(0!=(s=checkLWpn(ri->lwpn)))
5094
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11477 times.
11477 ret=((int32_t)(((weapon*)(s))->yofs-(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset)))*10000;
5095
5096 11477 break;
5097
5098 case LWPNSHADOWXOFS:
5099 if(0!=(s=checkLWpn(ri->lwpn)))
5100 ret=((int32_t)(((weapon*)(s))->shadowxofs))*10000;
5101
5102 break;
5103
5104 case LWPNSHADOWYOFS:
5105 if(0!=(s=checkLWpn(ri->lwpn)))
5106 ret=((int32_t)(((weapon*)(s))->shadowyofs))*10000;
5107
5108 break;
5109
5110 case LWPNTOTALDYOFFS:
5111 if(0!=(s=checkLWpn(ri->lwpn)))
5112 ret = ((int32_t)(((weapon*)(s))->yofs-(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset))
5113 + ((((weapon*)(s))->switch_hooked && Hero.switchhookstyle == swRISE)
5114 ? -(8-(abs(Hero.switchhookclk-32)/4)) : 0)) * 10000;
5115 break;
5116
5117 case LWPNZOFS:
5118
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(0!=(s=checkLWpn(ri->lwpn)))
5119 6 ret=((int32_t)(((weapon*)(s))->zofs))*10000;
5120
5121 6 break;
5122
5123 case LWPNHXSZ:
5124
2/2
✓ Branch 0 taken 15492 times.
✓ Branch 1 taken 267550 times.
283042 if(0!=(s=checkLWpn(ri->lwpn)))
5125 267550 ret=(((weapon*)(s))->hit_width)*10000;
5126
5127 283042 break;
5128
5129 case LWPNHYSZ:
5130
2/2
✓ Branch 0 taken 269504 times.
✓ Branch 1 taken 15492 times.
284996 if(0!=(s=checkLWpn(ri->lwpn)))
5131 269504 ret=(((weapon*)(s))->hit_height)*10000;
5132
5133 284996 break;
5134
5135 case LWPNHZSZ:
5136
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36540 times.
36540 if(0!=(s=checkLWpn(ri->lwpn)))
5137 36540 ret=(((weapon*)(s))->hzsz)*10000;
5138
5139 36540 break;
5140
5141 case LWPNTXSZ:
5142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32019 times.
32019 if(0!=(s=checkLWpn(ri->lwpn)))
5143 32019 ret=(((weapon*)(s))->txsz)*10000;
5144
5145 32019 break;
5146
5147 case LWPNTYSZ:
5148
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32019 times.
32019 if(0!=(s=checkLWpn(ri->lwpn)))
5149 32019 ret=(((weapon*)(s))->tysz)*10000;
5150
5151 32019 break;
5152
5153 case LWPNMISCD:
5154
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 1668126 times.
1668140 if(0!=(s=checkLWpn(ri->lwpn)))
5155 {
5156 1668126 int32_t a = vbound(ri->d[rINDEX]/10000,0,31);
5157 1668126 ret=(((weapon*)(s))->miscellaneous[a]);
5158 1668126 }
5159
5160 1668140 break;
5161
5162 case LWPNCOLLDET:
5163
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5455 times.
5455 if(0!=(s=checkLWpn(ri->lwpn)))
5164 5455 ret=(((weapon*)(s))->scriptcoldet)*10000;
5165
5166 5455 break;
5167
5168 case LWPNENGINEANIMATE:
5169 if(0!=(s=checkLWpn(ri->lwpn)))
5170 ret=(((weapon*)(s))->do_animation)*10000;
5171
5172 break;
5173
5174 case LWPNPARENT:
5175 if(0!=(s=checkLWpn(ri->lwpn)))
5176 ret=(((weapon*)(s))->parentitem)*10000;
5177
5178 break;
5179
5180 case LWPNLEVEL:
5181 if(0!=(s=checkLWpn(ri->lwpn)))
5182 ret=(((weapon*)(s))->type)*10000;
5183
5184 break;
5185
5186 case LWPNSCRIPT:
5187
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(0!=(s=checkLWpn(ri->lwpn)))
5188 3 ret=(((weapon*)(s))->weaponscript)*10000;
5189
5190 3 break;
5191
5192 case LWPNUSEWEAPON:
5193
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60075 times.
60075 if(0!=(s=checkLWpn(ri->lwpn)))
5194 60075 ret=(((weapon*)(s))->useweapon)*10000;
5195
5196 60075 break;
5197
5198 case LWPNUSEDEFENCE:
5199 if(0!=(s=checkLWpn(ri->lwpn)))
5200 ret=(((weapon*)(s))->usedefence)*10000;
5201
5202 break;
5203
5204 case LWPNINITD:
5205 {
5206 180 int32_t a = vbound((ri->d[rINDEX] / 10000),0,7);
5207
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
180 if(0!=(s=checkLWpn(ri->lwpn)))
5208 {
5209 180 ret=(((weapon*)(s))->weap_initd[a]);
5210 180 }
5211 180 break;
5212 }
5213
5214 case LWEAPONSCRIPTUID:
5215 if(0!=(s=checkLWpn(ri->lwpn)))
5216 ret=(((weapon*)(s))->getUID());
5217
5218 break;
5219
5220 case LWPNROTATION:
5221 if ( get_qr(qr_OLDSPRITEDRAWS) )
5222 {
5223 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
5224 ret = -1; break;
5225 }
5226 if(0!=(s=checkLWpn(ri->lwpn)))
5227 ret=((weapon*)(s))->rotation*10000;
5228
5229 break;
5230
5231 case LWPNFALLCLK:
5232
1/2
✓ Branch 0 taken 1552 times.
✗ Branch 1 not taken.
1552 if(0!=(s=checkLWpn(ri->lwpn)))
5233 {
5234 1552 ret = ((weapon*)(s))->fallclk * 10000;
5235 1552 }
5236 1552 break;
5237
5238 case LWPNFALLCMB:
5239 if(0!=(s=checkLWpn(ri->lwpn)))
5240 {
5241 ret = ((weapon*)(s))->fallCombo * 10000;
5242 }
5243 break;
5244
5245 case LWPNDROWNCLK:
5246 if(0!=(s=checkLWpn(ri->lwpn)))
5247 {
5248 ret = ((weapon*)(s))->drownclk * 10000;
5249 }
5250 break;
5251
5252 case LWPNDROWNCMB:
5253 if(0!=(s=checkLWpn(ri->lwpn)))
5254 {
5255 ret = ((weapon*)(s))->drownCombo * 10000;
5256 }
5257 break;
5258
5259 case LWPNFAKEZ:
5260 if(0!=(s=checkLWpn(ri->lwpn)))
5261 {
5262 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
5263 {
5264 ret=(((weapon*)(s))->fakez).getZLong();
5265 }
5266 else
5267 ret=((int32_t)((weapon*)(s))->fakez)*10000;
5268 }
5269 break;
5270
5271 case LWPNMOVEFLAGS:
5272 {
5273
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1551 times.
1551 if(0!=(s=checkLWpn(ri->lwpn)))
5274 {
5275 1551 int32_t indx = ri->d[rINDEX]/10000;
5276
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1551 times.
1551 if(BC::checkIndex(indx, 0, 10) != SH::_NoError)
5277 ret = 0; //false
5278 else
5279 {
5280 //All bits, in order, of a single byte; just use bitwise
5281 1551 ret = (((weapon*)(s))->moveflags & (1<<indx)) ? 10000 : 0;
5282 }
5283 1551 }
5284 1551 break;
5285 }
5286 case LWPNFLAGS:
5287 {
5288 if(0!=(s=checkLWpn(ri->lwpn)))
5289 {
5290 int32_t indx = ri->d[rINDEX]/10000;
5291 if(BC::checkIndex(indx, 0, WFLAG_MAX-1) != SH::_NoError)
5292 ret = 0; //false
5293 else
5294 {
5295 //All bits, in order, of a single byte; just use bitwise
5296 ret = (((weapon*)(s))->misc_wflags & (1<<indx)) ? 10000 : 0;
5297 }
5298 }
5299 break;
5300 }
5301 case LWPNSPRITES:
5302 {
5303 if(0!=(s=checkLWpn(ri->lwpn)))
5304 {
5305 int32_t indx = ri->d[rINDEX]/10000;
5306 if(BC::checkIndex(indx, 0, WPNSPR_MAX-1) != SH::_NoError)
5307 ret = -10000;
5308 else
5309 ret = ((weapon*)(s))->misc_wsprites[indx]*10000;
5310 }
5311 break;
5312 }
5313 case LWPNBURNLIGHTRADIUS:
5314 {
5315 if(0!=(s=checkLWpn(ri->lwpn)))
5316 {
5317 int32_t indx = ri->d[rINDEX]/10000;
5318 if(BC::checkIndex(indx, 0, WPNSPR_MAX-1) != SH::_NoError)
5319 ret = -10000;
5320 else
5321 ret = ((weapon*)(s))->light_rads[indx]*10000;
5322 }
5323 break;
5324 }
5325
5326 case LWPNGLOWRAD:
5327
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48553 times.
48553 if(0!=(s=checkLWpn(ri->lwpn)))
5328 {
5329 48553 ret = ((weapon*)(s))->glowRad * 10000;
5330 48553 }
5331 48553 break;
5332
5333 case LWPNGLOWSHP:
5334 if(0!=(s=checkLWpn(ri->lwpn)))
5335 {
5336 ret = ((weapon*)(s))->glowShape * 10000;
5337 }
5338 break;
5339
5340 case LWPNUNBL:
5341 if(0!=(s=checkLWpn(ri->lwpn)))
5342 {
5343 ret = ((weapon*)(s))->unblockable * 10000;
5344 }
5345 break;
5346
5347 case LWPNSHADOWSPR:
5348 if(0!=(s=checkLWpn(ri->lwpn)))
5349 {
5350 ret = ((weapon*)(s))->spr_shadow * 10000;
5351 }
5352 break;
5353 case LWSWHOOKED:
5354 if(0!=(s=checkLWpn(ri->lwpn)))
5355 {
5356 ret = s->switch_hooked ? 10000 : 0;
5357 }
5358 break;
5359 case LWPNTIMEOUT:
5360 if(0!=(s=checkLWpn(ri->lwpn)))
5361 {
5362 ret = ((weapon*)(s))->weap_timeout * 10000;
5363 }
5364 break;
5365 case LWPNDEATHITEM:
5366 if(0!=(s=checkLWpn(ri->lwpn)))
5367 {
5368 ret = ((weapon*)(s))->death_spawnitem * 10000;
5369 }
5370 break;
5371 case LWPNDEATHDROPSET:
5372 if(0!=(s=checkLWpn(ri->lwpn)))
5373 {
5374 ret = ((weapon*)(s))->death_spawndropset * 10000;
5375 }
5376 break;
5377 case LWPNDEATHIPICKUP:
5378 if(0!=(s=checkLWpn(ri->lwpn)))
5379 {
5380 ret = ((weapon*)(s))->death_item_pflags * 10000;
5381 }
5382 break;
5383 case LWPNDEATHSPRITE:
5384 if(0!=(s=checkLWpn(ri->lwpn)))
5385 {
5386 ret = ((weapon*)(s))->death_sprite * 10000;
5387 }
5388 break;
5389 case LWPNDEATHSFX:
5390 if(0!=(s=checkLWpn(ri->lwpn)))
5391 {
5392 ret = ((weapon*)(s))->death_sfx * 10000;
5393 }
5394 break;
5395 case LWPNLIFTLEVEL:
5396 if(0!=(s=checkLWpn(ri->lwpn)))
5397 {
5398 ret = ((weapon*)(s))->lift_level * 10000;
5399 }
5400 break;
5401 case LWPNLIFTTIME:
5402 if(0!=(s=checkLWpn(ri->lwpn)))
5403 {
5404 ret = ((weapon*)(s))->lift_time * 10000;
5405 }
5406 break;
5407 case LWPNLIFTHEIGHT:
5408 if(0!=(s=checkLWpn(ri->lwpn)))
5409 {
5410 ret = ((weapon*)(s))->lift_height.getZLong();
5411 }
5412 break;
5413
5414 ///----------------------------------------------------------------------------------------------------//
5415 //EWeapon Variables
5416 case EWPNSCALE:
5417 if ( get_qr(qr_OLDSPRITEDRAWS) )
5418 {
5419 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
5420 ret = -1; break;
5421 }
5422 if(0!=(s=checkEWpn(ri->ewpn)))
5423 ret=((int32_t)((weapon*)(s))->scale)*100.0;
5424
5425 break;
5426
5427 case EWPNX:
5428
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4354386 times.
4354386 if(0!=(s=checkEWpn(ri->ewpn)))
5429 {
5430
2/2
✓ Branch 0 taken 219258 times.
✓ Branch 1 taken 4135128 times.
4354386 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
5431 {
5432 219258 ret=(((weapon*)(s))->x).getZLong();
5433 219258 }
5434 else
5435 4135128 ret=((int32_t)((weapon*)(s))->x)*10000;
5436 4354386 }
5437 4354386 break;
5438
5439 case SPRITEMAXEWPN:
5440 {
5441 //No bounds check, as this is a universal function and works from NULL pointers!
5442 ret = Ewpns.getMax() * 10000;
5443 break;
5444 }
5445
5446 case EWPNY:
5447
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4354484 times.
4354484 if(0!=(s=checkEWpn(ri->ewpn)))
5448 {
5449
2/2
✓ Branch 0 taken 219111 times.
✓ Branch 1 taken 4135373 times.
4354484 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
5450 {
5451 219111 ret=(((weapon*)(s))->y).getZLong();
5452 219111 }
5453 else
5454 4135373 ret=((int32_t)((weapon*)(s))->y)*10000;
5455 4354484 }
5456 4354484 break;
5457
5458 case EWPNZ:
5459
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 552907 times.
552907 if(0!=(s=checkEWpn(ri->ewpn)))
5460 {
5461
2/2
✓ Branch 0 taken 1432 times.
✓ Branch 1 taken 551475 times.
552907 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
5462 {
5463 1432 ret=(((weapon*)(s))->z).getZLong();
5464 1432 }
5465 else
5466 551475 ret=((int32_t)((weapon*)(s))->z)*10000;
5467 552907 }
5468 552907 break;
5469
5470 case EWPNJUMP:
5471 if(0!=(s=checkEWpn(ri->ewpn)))
5472 {
5473 ret = ((weapon*)(s))->fall.getZLong() / -100;
5474 if (get_qr(qr_SPRITE_JUMP_IS_TRUNCATED)) ret = trunc(ret / 10000) * 10000;
5475 }
5476
5477 break;
5478
5479 case EWPNFAKEJUMP:
5480 if(0!=(s=checkEWpn(ri->ewpn)))
5481 {
5482 ret = ((weapon*)(s))->fakefall.getZLong() / -100;
5483 if (get_qr(qr_SPRITE_JUMP_IS_TRUNCATED)) ret = trunc(ret / 10000) * 10000;
5484 }
5485
5486 break;
5487
5488 case EWPNDIR:
5489
1/2
✓ Branch 0 taken 61563 times.
✗ Branch 1 not taken.
61563 if(0!=(s=checkEWpn(ri->ewpn)))
5490 61563 ret=((weapon*)(s))->dir*10000;
5491
5492 61563 break;
5493
5494 case EWPNLEVEL:
5495
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2845 times.
2845 if(0!=(s=checkEWpn(ri->ewpn)))
5496 2845 ret=((weapon*)(s))->type*10000;
5497
5498 2845 break;
5499
5500 case EWPNGRAVITY:
5501 if(0!=(s=checkEWpn(ri->ewpn)))
5502 ret=((((weapon*)(s))->moveflags & move_obeys_grav) ? 10000 : 0);
5503
5504 break;
5505
5506 case EWPNSTEP:
5507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 610345 times.
610345 if(0!=(s=checkEWpn(ri->ewpn)))
5508 {
5509
3/4
✓ Branch 0 taken 610183 times.
✓ Branch 1 taken 162 times.
✓ Branch 2 taken 610183 times.
✗ Branch 3 not taken.
610345 if ( get_qr(qr_STEP_IS_FLOAT) || replay_is_active() )
5510 {
5511 610345 ret=((weapon*)s)->step.getZLong() * 100;
5512 610345 }
5513 //old, buggy code replication, round two: Go! -Z
5514 //else ret = ( ( ( ((weapon*)s)->step ) * 100.0 ).getZLong() );
5515 //old, buggy code replication, round FOUR: Go! -Z
5516 else ret = (int32_t)((float)((weapon*)s)->step * 1000000.0);
5517 610345 }
5518 //else
5519 //{
5520 //old, buggy code replication, round THREE: Go! -Z
5521 // double tmp = ( ((weapon*)s)->step.getFloat() ) * 1000000.0;
5522 // ret = int32_t(tmp);
5523 //}
5524 610345 break;
5525
5526 case EWPNANGLE:
5527
1/2
✓ Branch 0 taken 718383 times.
✗ Branch 1 not taken.
718383 if(0!=(s=checkEWpn(ri->ewpn)))
5528 718383 ret=(int32_t)(((weapon*)(s))->angle*10000);
5529
5530 718383 break;
5531
5532 case EWPNDEGANGLE:
5533 if(0!=(s=checkEWpn(ri->ewpn)))
5534 {
5535 ret=(int32_t)(((weapon*)(s))->angle*(180.0 / PI)*10000);
5536 }
5537
5538 break;
5539
5540 case EWPNVX:
5541 if(0!=(s=checkEWpn(ri->ewpn)))
5542 {
5543 if (((weapon*)(s))->angular)
5544 ret = int32_t(zc::math::Cos(((weapon*)s)->angle)*10000.0*((weapon*)s)->step);
5545 else
5546 {
5547 switch(NORMAL_DIR(((weapon*)(s))->dir))
5548 {
5549 case l_up:
5550 case l_down:
5551 case left:
5552 ret = int32_t(-10000.0*((weapon*)s)->step);
5553 break;
5554 case r_up:
5555 case r_down:
5556 case right:
5557 ret = int32_t(10000.0*((weapon*)s)->step);
5558 break;
5559
5560 default:
5561 ret = 0;
5562 break;
5563 }
5564 }
5565 }
5566
5567 break;
5568
5569 case EWPNVY:
5570 if(0!=(s=checkEWpn(ri->ewpn)))
5571 {
5572 if (((weapon*)(s))->angular)
5573 ret = int32_t(zc::math::Sin(((weapon*)s)->angle)*10000.0*((weapon*)s)->step);
5574 else
5575 {
5576 switch(NORMAL_DIR(((weapon*)(s))->dir))
5577 {
5578 case l_up:
5579 case r_up:
5580 case up:
5581 ret = int32_t(-10000.0*((weapon*)s)->step);
5582 break;
5583 case l_down:
5584 case r_down:
5585 case down:
5586 ret = int32_t(10000.0*((weapon*)s)->step);
5587 break;
5588
5589 default:
5590 ret = 0;
5591 break;
5592 }
5593 }
5594 }
5595
5596 break;
5597
5598
5599 case EWPNANGULAR:
5600
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 136793 times.
136793 if(0!=(s=checkEWpn(ri->ewpn)))
5601 136793 ret=((weapon*)(s))->angular*10000;
5602
5603 136793 break;
5604
5605 case EWPNAUTOROTATE:
5606 if(0!=(s=checkEWpn(ri->ewpn)))
5607 ret=((weapon*)(s))->autorotate*10000;
5608
5609 break;
5610
5611 case EWPNBEHIND:
5612 if(0!=(s=checkEWpn(ri->ewpn)))
5613 ret=((weapon*)(s))->behind*10000;
5614
5615 break;
5616
5617 case EWPNDRAWTYPE:
5618
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46359 times.
46359 if(0!=(s=checkEWpn(ri->ewpn)))
5619 46359 ret=((weapon*)(s))->drawstyle*10000;
5620
5621 46359 break;
5622
5623 case EWPNPOWER:
5624
1/2
✓ Branch 0 taken 90304 times.
✗ Branch 1 not taken.
90304 if(0!=(s=checkEWpn(ri->ewpn)))
5625 90304 ret=((weapon*)(s))->power*10000;
5626
5627 90304 break;
5628
5629 case EWPNDEAD:
5630
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6052 times.
6052 if(0!=(s=checkEWpn(ri->ewpn)))
5631 6052 ret=((weapon*)(s))->dead*10000;
5632
5633 6052 break;
5634
5635 case EWPNID:
5636
2/2
✓ Branch 0 taken 72689 times.
✓ Branch 1 taken 2727389 times.
2800078 if(0!=(s=checkEWpn(ri->ewpn)))
5637 2727389 ret=((weapon*)(s))->id*10000;
5638
5639 2800078 break;
5640
5641 case EWPNTILE:
5642
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 205013 times.
205013 if(0!=(s=checkEWpn(ri->ewpn)))
5643 205013 ret=((weapon*)(s))->tile*10000;
5644
5645 205013 break;
5646
5647 case EWPNSCRIPTTILE:
5648 if(0!=(s=checkEWpn(ri->ewpn)))
5649 ret=((weapon*)(s))->scripttile*10000;
5650
5651 break;
5652
5653 case EWPNSCRIPTFLIP:
5654 if(0!=(s=checkEWpn(ri->ewpn)))
5655 ret=((weapon*)(s))->scriptflip*10000;
5656
5657 break;
5658
5659 case EWPNCSET:
5660
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 65315 times.
65315 if(0!=(s=checkEWpn(ri->ewpn)))
5661 65315 ret=((weapon*)(s))->cs*10000;
5662
5663 65315 break;
5664
5665 case EWPNFLASHCSET:
5666 if(0!=(s=checkEWpn(ri->ewpn)))
5667 ret=(((weapon*)(s))->o_cset>>4)*10000;
5668
5669 break;
5670
5671 case EWPNFRAMES:
5672
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
96 if(0!=(s=checkEWpn(ri->ewpn)))
5673 96 ret=((weapon*)(s))->frames*10000;
5674
5675 96 break;
5676
5677 case EWPNFRAME:
5678 if(0!=(s=checkEWpn(ri->ewpn)))
5679 ret=((weapon*)(s))->aframe*10000;
5680
5681 break;
5682
5683 case EWPNASPEED:
5684
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
96 if(0!=(s=checkEWpn(ri->ewpn)))
5685 96 ret=((weapon*)(s))->o_speed*10000;
5686
5687 96 break;
5688
5689 case EWPNFLASH:
5690 if(0!=(s=checkEWpn(ri->ewpn)))
5691 ret=((weapon*)(s))->flash*10000;
5692
5693 break;
5694
5695 case EWPNFLIP:
5696
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12006 times.
12006 if(0!=(s=checkEWpn(ri->ewpn)))
5697 12006 ret=((weapon*)(s))->flip*10000;
5698
5699 12006 break;
5700
5701 case EWPNROTATION:
5702
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 218 times.
218 if ( get_qr(qr_OLDSPRITEDRAWS) )
5703 {
5704 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'");
5705 break;
5706 }
5707
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 218 times.
218 if(0!=(s=checkEWpn(ri->ewpn)))
5708 218 ret=((weapon*)(s))->rotation*10000;
5709
5710 218 break;
5711
5712 case EWPNCOUNT:
5713 6012051 ret=Ewpns.Count()*10000;
5714 6012051 break;
5715
5716 case EWPNEXTEND:
5717 if(0!=(s=checkEWpn(ri->ewpn)))
5718 ret=((weapon*)(s))->extend*10000;
5719
5720 break;
5721
5722 case EWPNOTILE:
5723
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10477 times.
10477 if(0!=(s=checkEWpn(ri->ewpn)))
5724 10477 ret=((weapon*)(s))->o_tile*10000;
5725
5726 10477 break;
5727
5728 case EWPNOCSET:
5729 if(0!=(s=checkEWpn(ri->ewpn)))
5730 ret=(((weapon*)(s))->o_cset&15)*10000;
5731
5732 break;
5733
5734 case EWPNHXOFS:
5735
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 157773 times.
157773 if(0!=(s=checkEWpn(ri->ewpn)))
5736 157773 ret=(((weapon*)(s))->hxofs)*10000;
5737
5738 157773 break;
5739
5740 case EWPNHYOFS:
5741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 157773 times.
157773 if(0!=(s=checkEWpn(ri->ewpn)))
5742 157773 ret=(((weapon*)(s))->hyofs)*10000;
5743
5744 157773 break;
5745
5746 case EWPNXOFS:
5747
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48464 times.
48464 if(0!=(s=checkEWpn(ri->ewpn)))
5748 48464 ret=((int32_t)(((weapon*)(s))->xofs))*10000;
5749
5750 48464 break;
5751
5752 case EWPNYOFS:
5753
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60558 times.
60558 if(0!=(s=checkEWpn(ri->ewpn)))
5754
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60558 times.
60558 ret=((int32_t)(((weapon*)(s))->yofs-(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset)))*10000;
5755
5756 60558 break;
5757
5758 case EWPNSHADOWXOFS:
5759 if(0!=(s=checkEWpn(ri->ewpn)))
5760 ret=((int32_t)(((weapon*)(s))->shadowxofs))*10000;
5761
5762 break;
5763
5764 case EWPNSHADOWYOFS:
5765 if(0!=(s=checkEWpn(ri->ewpn)))
5766 ret=((int32_t)(((weapon*)(s))->shadowyofs))*10000;
5767
5768 break;
5769 case EWPNTOTALDYOFFS:
5770 if(0!=(s=checkLWpn(ri->lwpn)))
5771 ret = ((int32_t)(((weapon*)(s))->yofs-(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset))
5772 + ((((weapon*)(s))->switch_hooked && Hero.switchhookstyle == swRISE)
5773 ? -(8-(abs(Hero.switchhookclk-32)/4)) : 0) * 10000);
5774 break;
5775
5776 case EWPNZOFS:
5777
1/2
✓ Branch 0 taken 1880 times.
✗ Branch 1 not taken.
1880 if(0!=(s=checkEWpn(ri->ewpn)))
5778 1880 ret=((int32_t)(((weapon*)(s))->zofs))*10000;
5779
5780 1880 break;
5781
5782 case EWPNHXSZ:
5783
1/2
✓ Branch 0 taken 149564 times.
✗ Branch 1 not taken.
149564 if(0!=(s=checkEWpn(ri->ewpn)))
5784 149564 ret=(((weapon*)(s))->hit_width)*10000;
5785
5786 149564 break;
5787
5788 case EWPNHYSZ:
5789
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149564 times.
149564 if(0!=(s=checkEWpn(ri->ewpn)))
5790 149564 ret=(((weapon*)(s))->hit_height)*10000;
5791
5792 149564 break;
5793
5794 case EWPNHZSZ:
5795
1/2
✓ Branch 0 taken 81355 times.
✗ Branch 1 not taken.
81355 if(0!=(s=checkEWpn(ri->ewpn)))
5796 81355 ret=(((weapon*)(s))->hzsz)*10000;
5797
5798 81355 break;
5799
5800 case EWPNTXSZ:
5801
1/2
✓ Branch 0 taken 125257 times.
✗ Branch 1 not taken.
125257 if(0!=(s=checkEWpn(ri->ewpn)))
5802 125257 ret=(((weapon*)(s))->txsz)*10000;
5803
5804 125257 break;
5805
5806 case EWPNTYSZ:
5807
1/2
✓ Branch 0 taken 125257 times.
✗ Branch 1 not taken.
125257 if(0!=(s=checkEWpn(ri->ewpn)))
5808 125257 ret=(((weapon*)(s))->tysz)*10000;
5809
5810 125257 break;
5811
5812 case EWPNMISCD:
5813
2/2
✓ Branch 0 taken 25064735 times.
✓ Branch 1 taken 3 times.
25064738 if(0!=(s=checkEWpn(ri->ewpn)))
5814 {
5815 25064735 int32_t a = vbound(ri->d[rINDEX]/10000,0,31);
5816 25064735 ret=(((weapon*)(s))->miscellaneous[a]);
5817 25064735 }
5818
5819 25064738 break;
5820
5821 case EWPNCOLLDET:
5822
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10565 times.
10565 if(0!=(s=checkEWpn(ri->ewpn)))
5823 10565 ret=(((weapon*)(s))->scriptcoldet)*10000;
5824
5825 10565 break;
5826
5827 case EWPNENGINEANIMATE:
5828 if(0!=(s=checkEWpn(ri->ewpn)))
5829 ret=(((weapon*)(s))->do_animation)*10000;
5830
5831 break;
5832
5833 case EWPNPARENT:
5834 if(0!=(s=checkEWpn(ri->ewpn)))
5835 ret= ((get_qr(qr_OLDEWPNPARENT)) ? (((weapon*)(s))->parentid)*10000 : (((weapon*)(s))->parentid));
5836
5837 break;
5838
5839 case EWEAPONSCRIPTUID:
5840 if(0!=(s=checkEWpn(ri->ewpn)))
5841 ret=(((weapon*)(s))->getUID());
5842
5843 break;
5844
5845 case EWPNPARENTUID:
5846 if(0!=(s=checkEWpn(ri->ewpn)))
5847 ret=(((weapon*)(s))->parent_uid);
5848
5849 break;
5850
5851 case EWPNSCRIPT:
5852
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 if(0!=(s=checkEWpn(ri->ewpn)))
5853 43 ret=(((weapon*)(s))->weaponscript)*10000;
5854
5855 43 break;
5856
5857 case EWPNINITD:
5858 {
5859 16680 int32_t a = vbound((ri->d[rINDEX] / 10000),0,7);
5860
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16680 times.
16680 if(0!=(s=checkEWpn(ri->ewpn)))
5861 {
5862 16680 ret=(((weapon*)(s))->weap_initd[a]);
5863 16680 }
5864 16680 break;
5865 }
5866
5867 case EWPNFALLCLK:
5868 if(0!=(s=checkEWpn(ri->ewpn)))
5869 {
5870 ret = ((weapon*)(s))->fallclk * 10000;
5871 }
5872 break;
5873
5874 case EWPNFALLCMB:
5875 if(0!=(s=checkEWpn(ri->ewpn)))
5876 {
5877 ret = ((weapon*)(s))->fallCombo * 10000;
5878 }
5879 break;
5880
5881 case EWPNDROWNCLK:
5882 if(0!=(s=checkEWpn(ri->ewpn)))
5883 {
5884 ret = ((weapon*)(s))->drownclk * 10000;
5885 }
5886 break;
5887
5888 case EWPNDROWNCMB:
5889 if(0!=(s=checkEWpn(ri->ewpn)))
5890 {
5891 ret = ((weapon*)(s))->drownCombo * 10000;
5892 }
5893 break;
5894 case EWPNFAKEZ:
5895 if(0!=(s=checkEWpn(ri->ewpn)))
5896 {
5897 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
5898 {
5899 ret=(((weapon*)(s))->fakez).getZLong();
5900 }
5901 else
5902 ret=((int32_t)((weapon*)(s))->fakez)*10000;
5903 }
5904 break;
5905
5906 case EWPNMOVEFLAGS:
5907 {
5908 if(0!=(s=checkEWpn(ri->ewpn)))
5909 {
5910 int32_t indx = ri->d[rINDEX]/10000;
5911 if(BC::checkIndex(indx, 0, 10) != SH::_NoError)
5912 ret = 0; //false
5913 else
5914 {
5915 //All bits, in order, of a single byte; just use bitwise
5916 ret = (((weapon*)(s))->moveflags & (1<<indx)) ? 10000 : 0;
5917 }
5918 }
5919 break;
5920 }
5921 case EWPNFLAGS:
5922 {
5923 if(0!=(s=checkEWpn(ri->ewpn)))
5924 {
5925 int32_t indx = ri->d[rINDEX]/10000;
5926 if(BC::checkIndex(indx, 0, WFLAG_MAX-1) != SH::_NoError)
5927 ret = 0; //false
5928 else
5929 {
5930 //All bits, in order, of a single byte; just use bitwise
5931 ret = (((weapon*)(s))->misc_wflags & (1<<indx)) ? 10000 : 0;
5932 }
5933 }
5934 break;
5935 }
5936 case EWPNSPRITES:
5937 {
5938 if(0!=(s=checkEWpn(ri->ewpn)))
5939 {
5940 int32_t indx = ri->d[rINDEX]/10000;
5941 if(BC::checkIndex(indx, 0, WPNSPR_MAX-1) != SH::_NoError)
5942 ret = -10000;
5943 else
5944 ret = ((weapon*)(s))->misc_wsprites[indx]*10000;
5945 }
5946 break;
5947 }
5948 case EWPNBURNLIGHTRADIUS:
5949 {
5950 if(0!=(s=checkEWpn(ri->ewpn)))
5951 {
5952 int32_t indx = ri->d[rINDEX]/10000;
5953 if(BC::checkIndex(indx, 0, WPNSPR_MAX-1) != SH::_NoError)
5954 ret = -10000;
5955 else
5956 ret = ((weapon*)(s))->light_rads[indx]*10000;
5957 }
5958 break;
5959 }
5960
5961 case EWPNGLOWRAD:
5962
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30735 times.
30735 if(0!=(s=checkEWpn(ri->ewpn)))
5963 {
5964 30735 ret = ((weapon*)(s))->glowRad * 10000;
5965 30735 }
5966 30735 break;
5967
5968 case EWPNGLOWSHP:
5969 if(0!=(s=checkEWpn(ri->ewpn)))
5970 {
5971 ret = ((weapon*)(s))->glowShape * 10000;
5972 }
5973 break;
5974
5975 case EWPNUNBL:
5976 if(0!=(s=checkEWpn(ri->ewpn)))
5977 {
5978 ret = ((weapon*)(s))->unblockable * 10000;
5979 }
5980 break;
5981
5982 case EWPNSHADOWSPR:
5983 if(0!=(s=checkEWpn(ri->ewpn)))
5984 {
5985 ret = ((weapon*)(s))->spr_shadow * 10000;
5986 }
5987 break;
5988 case EWSWHOOKED:
5989 if(0!=(s=checkEWpn(ri->ewpn)))
5990 {
5991 ret = s->switch_hooked ? 10000 : 0;
5992 }
5993 break;
5994 case EWPNTIMEOUT:
5995 if(0!=(s=checkEWpn(ri->ewpn)))
5996 {
5997 ret = ((weapon*)(s))->weap_timeout * 10000;
5998 }
5999 break;
6000 case EWPNDEATHITEM:
6001 if(0!=(s=checkEWpn(ri->ewpn)))
6002 {
6003 ret = ((weapon*)(s))->death_spawnitem * 10000;
6004 }
6005 break;
6006 case EWPNDEATHDROPSET:
6007 if(0!=(s=checkEWpn(ri->ewpn)))
6008 {
6009 ret = ((weapon*)(s))->death_spawndropset * 10000;
6010 }
6011 break;
6012 case EWPNDEATHIPICKUP:
6013 if(0!=(s=checkEWpn(ri->ewpn)))
6014 {
6015 ret = ((weapon*)(s))->death_item_pflags * 10000;
6016 }
6017 break;
6018 case EWPNDEATHSPRITE:
6019 if(0!=(s=checkEWpn(ri->ewpn)))
6020 {
6021 ret = ((weapon*)(s))->death_sprite * 10000;
6022 }
6023 break;
6024 case EWPNDEATHSFX:
6025 if(0!=(s=checkEWpn(ri->ewpn)))
6026 {
6027 ret = ((weapon*)(s))->death_sfx * 10000;
6028 }
6029 break;
6030 case EWPNLIFTLEVEL:
6031 if(0!=(s=checkEWpn(ri->ewpn)))
6032 {
6033 ret = ((weapon*)(s))->lift_level * 10000;
6034 }
6035 break;
6036 case EWPNLIFTTIME:
6037 if(0!=(s=checkEWpn(ri->ewpn)))
6038 {
6039 ret = ((weapon*)(s))->lift_time * 10000;
6040 }
6041 break;
6042 case EWPNLIFTHEIGHT:
6043 if(0!=(s=checkEWpn(ri->ewpn)))
6044 {
6045 ret = ((weapon*)(s))->lift_height.getZLong();
6046 }
6047 break;
6048
6049 case GAMEPLAYFIELDOFS:
6050 ret = playing_field_offset*10000;
6051 break;
6052
6053 case GETPIXEL:
6054 ret=FFCore.do_getpixel();
6055 break;
6056
6057 case SCREENSTATED:
6058 {
6059 8380661 int mi = mapind(cur_map, ri->screenref);
6060
1/2
✓ Branch 0 taken 8380661 times.
✗ Branch 1 not taken.
8380661 if(mi<0) {ret = 0;break;}
6061 8380661 ret=((game->maps[mi]>>((ri->d[rINDEX]/10000)))&1)?10000:0;
6062 }
6063 8380661 break;
6064 case SCREENEXSTATED:
6065 {
6066 1754 int mi = mapind(cur_map, ri->screenref);
6067
1/2
✓ Branch 0 taken 1754 times.
✗ Branch 1 not taken.
1754 if(mi<0) {ret = 0;break;}
6068 1754 ret=((game->xstates[mi]>>((ri->d[rINDEX]/10000)))&1)?10000:0;
6069 }
6070 1754 break;
6071 case SCREENLENSSHOWS:
6072 {
6073 int ind = ri->d[rINDEX]/10000;
6074 if(ind < 0 || ind > 6)
6075 scripting_log_error_with_context("Invalid index: {}", ind);
6076 else ret = (get_scr(ri->screenref)->lens_show & (1<<ind)) ? 10000 : 0;
6077 break;
6078 }
6079 case SCREENLENSHIDES:
6080 {
6081 int ind = ri->d[rINDEX]/10000;
6082 if(ind < 0 || ind > 6)
6083 scripting_log_error_with_context("Invalid index: {}", ind);
6084 else ret = (get_scr(ri->screenref)->lens_hide & (1<<ind)) ? 10000 : 0;
6085 break;
6086 }
6087 case SCREENSCRDATASIZE:
6088 {
6089 int index = map_screen_index(cur_map, ri->screenref);
6090 if (index < 0) break;
6091 ret = 10000*game->scriptDataSize(index);
6092 break;
6093 }
6094 case SCREENSCRDATA:
6095 {
6096 int index = map_screen_index(cur_map, ri->screenref);
6097 if (index < 0) break;
6098 size_t indx = ri->d[rINDEX]/10000;
6099 if(indx >= game->scriptDataSize(index))
6100 {
6101 scripting_log_error_with_context("Invalid index: {}", indx);
6102 break;
6103 }
6104 ret = game->screen_data[index][indx];
6105 break;
6106 }
6107
6108 case DISTANCE:
6109 {
6110 792465 double x1 = double(ri->d[rSFTEMP] / 10000.0);
6111 792465 double y1 = double(ri->d[rINDEX] / 10000.0);
6112 792465 double x2 = double(ri->d[rINDEX2] / 10000.0);
6113 792465 double y2 = double(ri->d[rEXP1] / 10000.0);
6114
6115
6116
6117 792465 int32_t result = FFCore.Distance(x1, y1, x2, y2);
6118 792465 ret = (result);
6119
6120 792465 break;
6121 }
6122 case LONGDISTANCE:
6123 {
6124 double x1 = double(ri->d[rSFTEMP]);
6125 double y1 = double(ri->d[rINDEX]);
6126 double x2 = double(ri->d[rINDEX2]);
6127 double y2 = double(ri->d[rEXP1]);
6128
6129
6130
6131 int32_t result = FFCore.LongDistance(x1, y1, x2, y2);
6132 ret = (result);
6133
6134 break;
6135 }
6136
6137 case DISTANCESCALE:
6138 {
6139 double x1 = (double)(ri->d[rSFTEMP] / 10000.0);
6140 double y1 = (double)(ri->d[rINDEX] / 10000.0);
6141 double x2 = (double)(ri->d[rINDEX2] / 10000.0);
6142 double y2 = (double)(ri->d[rEXP1] / 10000.0);
6143
6144 int32_t scale = (ri->d[rWHAT_NO_7]/10000);
6145
6146 if ( !scale ) scale = 10000;
6147 int32_t result = FFCore.Distance(x1, y1, x2, y2, scale);
6148 ret = (result);
6149
6150 break;
6151 }
6152 case LONGDISTANCESCALE:
6153 {
6154 double x1 = (double)(ri->d[rSFTEMP]);
6155 double y1 = (double)(ri->d[rINDEX]);
6156 double x2 = (double)(ri->d[rINDEX2]);
6157 double y2 = (double)(ri->d[rEXP1]);
6158
6159 int32_t scale = (ri->d[rWHAT_NO_7]);
6160
6161 if ( !scale ) scale = 1;
6162 int32_t result = FFCore.LongDistance(x1, y1, x2, y2, scale);
6163 ret = (result);
6164
6165 break;
6166 }
6167
6168 case SCREENSTATEDD:
6169 {
6170 // Gah! >:( Screen state is stored in game->maps, which uses 128 screens per map,
6171 // but the compiler multiplies the map number by 136, so it has to be corrected here.
6172 // Yeah, the compiler could be fixed, but that wouldn't cover existing quests...
6173 20977804 int32_t mi = ri->d[rINDEX] / 10000;
6174 20977804 mi -= 8*((ri->d[rINDEX] / 10000) / MAPSCRS);
6175
6176
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20977804 times.
20977804 if(BC::checkMapID(mi>>7) == SH::_NoError)
6177 20977804 ret=(game->maps[mi] >> (ri->d[rINDEX2] / 10000) & 1) ? 10000 : 0;
6178 else
6179 ret=0;
6180
6181 20977804 break;
6182 }
6183
6184 case GAMEGUYCOUNTD:
6185 {
6186 int mi = mapind(cur_map, ri->d[rINDEX] / 10000);
6187 ret = game->guys[mi] * 10000;
6188 break;
6189 }
6190
6191 case ALLOCATEBITMAPR:
6192 225 ret=FFCore.get_free_bitmap();
6193 225 break;
6194
6195 case GETMIDI:
6196 63717 ret=(currmidi-(ZC_MIDI_COUNT-1))*10000;
6197 63717 break;
6198
6199 case CURDSCR:
6200 {
6201 11270839 int32_t di = (get_currscr()-DMaps[get_currdmap()].xoff);
6202
2/2
✓ Branch 0 taken 4460784 times.
✓ Branch 1 taken 6810055 times.
11270839 ret=(DMaps[get_currdmap()].type==dmOVERW ? cur_screen : di)*10000;
6203 }
6204 11270839 break;
6205
6206 case GAMEMAXMAPS:
6207 96 ret = (map_count)*10000;
6208 96 break;
6209 case GAMENUMMESSAGES:
6210 ret = (msg_count-1) * 10000;
6211 break;
6212
6213 case CURDMAP:
6214 58183880 ret=cur_dmap*10000;
6215 58183880 break;
6216
6217 case CURLEVEL:
6218 15080301 ret=DMaps[get_currdmap()].level*10000;
6219 15080301 break;
6220
6221 case GAMECLICKFREEZE:
6222 ret=disableClickToFreeze?0:10000;
6223 break;
6224
6225
6226 case NOACTIVESUBSC:
6227 ret=Hero.stopSubscreenFalling()?10000:0;
6228 break;///----------------------------------------------------------------------------------------------------//
6229 //BottleTypes
6230 case BOTTLECOUNTER:
6231 {
6232 if(bottletype* ptr = checkBottleData(ri->bottletyperef))
6233 {
6234 int32_t indx = ri->d[rINDEX]/10000;
6235 if(unsigned(indx) > 2)
6236 {
6237 scripting_log_error_with_context("Invalid index: {}", indx);
6238 ret = -10000L;
6239 break;
6240 }
6241 ret = 10000L * ptr->counter[indx];
6242 }
6243 else ret = -10000L;
6244 }
6245 break;
6246
6247 case BOTTLEAMOUNT:
6248 {
6249 if(bottletype* ptr = checkBottleData(ri->bottletyperef))
6250 {
6251 int32_t indx = ri->d[rINDEX]/10000;
6252 if(unsigned(indx) > 2)
6253 {
6254 scripting_log_error_with_context("Invalid index: {}", indx);
6255 ret = -10000L;
6256 break;
6257 }
6258 ret = 10000L * ptr->amount[indx];
6259 }
6260 else ret = -10000L;
6261 }
6262 break;
6263
6264 case BOTTLEPERCENT:
6265 {
6266 if(bottletype* ptr = checkBottleData(ri->bottletyperef))
6267 {
6268 int32_t indx = ri->d[rINDEX]/10000;
6269 if(unsigned(indx) > 2)
6270 {
6271 scripting_log_error_with_context("Invalid index: {}", indx);
6272 ret = -10000L;
6273 break;
6274 }
6275 ret = (ptr->flags & (1<<indx)) ? 10000L : 0;
6276 }
6277 else ret = -10000L;
6278 }
6279 break;
6280
6281 case BOTTLEFLAGS:
6282 {
6283 if(bottletype* ptr = checkBottleData(ri->bottletyperef))
6284 {
6285 int32_t indx = ri->d[rINDEX]/10000;
6286 if(unsigned(indx) > 3)
6287 {
6288 scripting_log_error_with_context("Invalid index: {}", indx);
6289 ret = -10000L;
6290 break;
6291 }
6292 int32_t flag = 0;
6293 switch(indx)
6294 {
6295 case 0: flag = BTFLAG_AUTOONDEATH; break;
6296 case 1: flag = BTFLAG_ALLOWIFFULL; break;
6297 case 2: flag = BTFLAG_CURESWJINX; break;
6298 case 3: flag = BTFLAG_CUREITJINX; break;
6299 case 4: flag = BTFLAG_CURESHJINX; break;
6300 }
6301 ret = (ptr->flags & flag) ? 10000L : 0;
6302 }
6303 else ret = -10000L;
6304 }
6305 break;
6306
6307 case BOTTLENEXT:
6308 {
6309 if(bottletype* ptr = checkBottleData(ri->bottletyperef))
6310 {
6311 ret = 10000L * ptr->next_type;
6312 }
6313 else ret = -10000L;
6314 }
6315 break;
6316 ///----------------------------------------------------------------------------------------------------//
6317 //BottleShops
6318 case BSHOPFILL:
6319 {
6320 if(bottleshoptype* ptr = checkBottleShopData(ri->bottleshopref))
6321 {
6322 int32_t indx = ri->d[rINDEX]/10000;
6323 if(unsigned(indx) > 2)
6324 {
6325 scripting_log_error_with_context("Invalid index: {}", indx);
6326 ret = -10000L;
6327 break;
6328 }
6329 ret = 10000L * ptr->fill[indx];
6330 }
6331 else ret = -10000L;
6332 }
6333 break;
6334
6335 case BSHOPCOMBO:
6336 {
6337 if(bottleshoptype* ptr = checkBottleShopData(ri->bottleshopref))
6338 {
6339 int32_t indx = ri->d[rINDEX]/10000;
6340 if(unsigned(indx) > 2)
6341 {
6342 scripting_log_error_with_context("Invalid index: {}", indx);
6343 ret = -10000L;
6344 break;
6345 }
6346 ret = 10000L * ptr->comb[indx];
6347 }
6348 else ret = -10000L;
6349 }
6350 break;
6351
6352 case BSHOPCSET:
6353 {
6354 if(bottleshoptype* ptr = checkBottleShopData(ri->bottleshopref))
6355 {
6356 int32_t indx = ri->d[rINDEX]/10000;
6357 if(unsigned(indx) > 2)
6358 {
6359 scripting_log_error_with_context("Invalid index: {}", indx);
6360 ret = -10000L;
6361 break;
6362 }
6363 ret = 10000L * ptr->cset[indx];
6364 }
6365 else ret = -10000L;
6366 }
6367 break;
6368
6369 case BSHOPPRICE:
6370 {
6371 if(bottleshoptype* ptr = checkBottleShopData(ri->bottleshopref))
6372 {
6373 int32_t indx = ri->d[rINDEX]/10000;
6374 if(unsigned(indx) > 2)
6375 {
6376 scripting_log_error_with_context("Invalid index: {}", indx);
6377 ret = -10000L;
6378 break;
6379 }
6380 ret = 10000L * ptr->price[indx];
6381 }
6382 else ret = -10000L;
6383 }
6384 break;
6385
6386 case BSHOPSTR:
6387 {
6388 if(bottleshoptype* ptr = checkBottleShopData(ri->bottleshopref))
6389 {
6390 int32_t indx = ri->d[rINDEX]/10000;
6391 if(unsigned(indx) > 2)
6392 {
6393 scripting_log_error_with_context("Invalid index: {}", indx);
6394 ret = -10000L;
6395 break;
6396 }
6397 ret = 10000L * ptr->str[indx];
6398 }
6399 else ret = -10000L;
6400 }
6401 break;
6402
6403 ///----------------------------------------------------------------------------------------------------//
6404 //Screen->ComboX
6405 #define GET_COMBO_VAR(member) \
6406 { \
6407 rpos_t rpos = (rpos_t)(ri->d[rINDEX] / 10000); \
6408 if(BC::checkComboRpos(rpos) != SH::_NoError) \
6409 { \
6410 ret = -10000; \
6411 } \
6412 else \
6413 ret = get_scr_for_rpos(rpos)->member[RPOS_TO_POS(rpos)]*10000; \
6414 }
6415
6416 case COMBODD:
6417
1/2
✓ Branch 0 taken 45964257 times.
✗ Branch 1 not taken.
45964257 GET_COMBO_VAR(data) break;
6418
6419 case COMBOCD:
6420
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2740280 times.
2740280 GET_COMBO_VAR(cset) break;
6421
6422 case COMBOFD:
6423
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13058666 times.
13058666 GET_COMBO_VAR(sflag) break;
6424
6425 #define GET_COMBO_VAR_BUF(member) \
6426 { \
6427 rpos_t rpos = (rpos_t)(ri->d[rINDEX] / 10000); \
6428 if(BC::checkComboRpos(rpos) != SH::_NoError) \
6429 { \
6430 ret = -10000; \
6431 } \
6432 else \
6433 ret = get_rpos_handle(rpos, 0).combo().member * 10000; \
6434 }
6435
6436 case COMBOTD:
6437
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54645118 times.
54645118 GET_COMBO_VAR_BUF(type) break;
6438
6439 case COMBOID:
6440
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7680829 times.
7680829 GET_COMBO_VAR_BUF(flag) break;
6441
6442 case COMBOSD:
6443 {
6444 211493 rpos_t rpos = (rpos_t)(ri->d[rINDEX] / 10000);
6445
6446
2/2
✓ Branch 0 taken 2400 times.
✓ Branch 1 taken 209093 times.
211493 if(BC::checkComboRpos(rpos) != SH::_NoError)
6447 2400 ret = -10000;
6448 else
6449 209093 ret = (get_rpos_handle(rpos, 0).combo().walk & 0xF) * 10000;
6450 }
6451 211493 break;
6452
6453 case COMBOED:
6454 {
6455 rpos_t rpos = (rpos_t)(ri->d[rINDEX] / 10000);
6456
6457 if(BC::checkComboRpos(rpos) != SH::_NoError)
6458 ret = -10000;
6459 else
6460 ret = ((get_rpos_handle(rpos, 0).combo().walk & 0xF0)>>4) * 10000;
6461 }
6462 break;
6463
6464 ///----------------------------------------------------------------------------------------------------//
6465 //Region
6466
6467 case REGION_WIDTH:
6468 {
6469 47264 ret = world_w * 10000;
6470 }
6471 47264 break;
6472
6473 case REGION_HEIGHT:
6474 {
6475 39568 ret = world_h * 10000;
6476 }
6477 39568 break;
6478
6479 case REGION_SCREEN_WIDTH:
6480 {
6481 64 ret = cur_region.screen_width * 10000;
6482 }
6483 64 break;
6484
6485 case REGION_SCREEN_HEIGHT:
6486 {
6487 20 ret = cur_region.screen_height * 10000;
6488 }
6489 20 break;
6490
6491 case REGION_NUM_COMBOS:
6492 {
6493 32 ret = region_num_rpos * 10000;
6494 }
6495 32 break;
6496
6497 case REGION_ID:
6498 {
6499 982758 ret = get_current_region_id() * 10000;
6500 }
6501 982758 break;
6502
6503 case REGION_ORIGIN_SCREEN:
6504 {
6505 ret = cur_screen;
6506 }
6507 break;
6508
6509 ///----------------------------------------------------------------------------------------------------//
6510 //Viewport
6511
6512 case VIEWPORT_TARGET:
6513 {
6514 ret = get_viewport_sprite()->uid;
6515 }
6516 break;
6517
6518 case VIEWPORT_MODE:
6519 {
6520 ret = (int)viewport_mode;
6521 }
6522 break;
6523
6524 case VIEWPORT_X:
6525 {
6526 24940 ret = viewport.x * 10000;
6527 }
6528 24940 break;
6529
6530 case VIEWPORT_Y:
6531 {
6532 21112 ret = viewport.y * 10000;
6533 }
6534 21112 break;
6535
6536 case VIEWPORT_WIDTH:
6537 {
6538 8014 ret = viewport.w * 10000;
6539 }
6540 8014 break;
6541
6542 case VIEWPORT_HEIGHT:
6543 {
6544 11842 ret = viewport.h * 10000;
6545 }
6546 11842 break;
6547
6548 ///----------------------------------------------------------------------------------------------------//
6549 //Screen Information
6550
6551 #define GET_SCREENDATA_VAR_INT32(member) \
6552 { \
6553 ret = (get_scr(ri->screenref)->member *10000); \
6554 } \
6555
6556 #define GET_SCREENDATA_VAR_INT16(member) \
6557 { \
6558 ret = (get_scr(ri->screenref)->member *10000); \
6559 } \
6560
6561 #define GET_SCREENDATA_VAR_BYTE(member) \
6562 { \
6563 ret = (get_scr(ri->screenref)->member *10000); \
6564 } \
6565
6566 #define GET_SCREENDATA_VAR_INDEX32(member, indexbound) \
6567 { \
6568 int32_t indx = ri->d[rINDEX] / 10000; \
6569 ret = (get_scr(ri->screenref)->member[indx] *10000); \
6570 } \
6571
6572 #define GET_SCREENDATA_VAR_INDEX16(member, indexbound) \
6573 { \
6574 int32_t indx = ri->d[rINDEX] / 10000; \
6575 ret = (get_scr(ri->screenref)->member[indx] *10000); \
6576 } \
6577
6578 #define GET_SCREENDATA_BYTE_INDEX(member, indexbound) \
6579 { \
6580 int32_t indx = ri->d[rINDEX] / 10000; \
6581 ret = (get_scr(ri->screenref)->member[indx] *10000); \
6582 } \
6583
6584 //byte
6585 #define GET_SCREENDATA_LAYER_INDEX(member, indexbound) \
6586 { \
6587 int32_t indx = ri->d[rINDEX] / 10000; \
6588 if (BC::checkIndex(indx, 1, indexbound) != SH::_NoError) \
6589 { \
6590 ret = -10000; \
6591 } \
6592 else \
6593 { \
6594 ret = (get_scr(ri->screenref)->member[indx-1] *10000); \
6595 } \
6596 } \
6597
6598 #define GET_SCREENDATA_BOOL_INDEX(member, indexbound) \
6599 { \
6600 int32_t indx = ri->d[rINDEX] / 10000; \
6601 if (BC::checkIndex(indx, 0, indexbound) != SH::_NoError) \
6602 { \
6603 ret = -10000; \
6604 } \
6605 else \
6606 { \
6607 ret = (get_scr(ri->screenref)->member[indx]?10000:0); \
6608 } \
6609 } \
6610
6611
6612 #define GET_SCREENDATA_FLAG(member, str, indexbound) \
6613 { \
6614 int32_t flag = (value/10000); \
6615 ret = (get_scr(ri->screenref)->member&flag) ? 10000 : 0); \
6616 } \
6617
6618 case SCREENDATAVALID: GET_SCREENDATA_VAR_BYTE(valid); break; //b
6619 case SCREENDATAGUY: GET_SCREENDATA_VAR_BYTE(guy); break; //b
6620 case SCREENDATASTRING: GET_SCREENDATA_VAR_INT32(str); break; //w
6621 case SCREENDATAROOM: GET_SCREENDATA_VAR_BYTE(room); break; //b
6622 case SCREENDATAITEM:
6623 {
6624 mapscr* scr = get_scr(ri->screenref);
6625 if(scr->hasitem)
6626 ret = (scr->item *10000);
6627 else ret = -10000;
6628 break;
6629 }
6630 case SCREENDATAHASITEM: GET_SCREENDATA_VAR_BYTE(hasitem); break; //b
6631 case SCREENDATATILEWARPTYPE: GET_SCREENDATA_BYTE_INDEX(tilewarptype, 3); break; //b, 4 of these
6632 //case SCREENDATATILEWARPOVFLAGS: GET_SCREENDATA_VAR_BYTE(tilewarpoverlayflags); break; //b, tilewarpoverlayflags
6633 case SCREENDATADOORCOMBOSET: GET_SCREENDATA_VAR_INT32(door_combo_set); break; //w
6634 7 case SCREENDATAWARPRETX: GET_SCREENDATA_BYTE_INDEX(warpreturnx, 3); break; //b, 4 of these
6635 7 case SCREENDATAWARPRETY: GET_SCREENDATA_BYTE_INDEX(warpreturny, 3); break; //b, 4 of these
6636 case SCREENDATAWARPRETURNC: GET_SCREENDATA_VAR_INT32(warpreturnc); break; //w
6637 case SCREENDATASTAIRX: GET_SCREENDATA_VAR_BYTE(stairx); break; //b
6638 case SCREENDATASTAIRY: GET_SCREENDATA_VAR_BYTE(stairy); break; //b
6639 case SCREENDATAITEMX: GET_SCREENDATA_VAR_BYTE(itemx); break; //itemx
6640 case SCREENDATAITEMY: GET_SCREENDATA_VAR_BYTE(itemy); break; //itemy
6641 1026 case SCREENDATACOLOUR: GET_SCREENDATA_VAR_INT32(color); break; //w
6642 case SCREENDATAENEMYFLAGS: GET_SCREENDATA_VAR_BYTE(flags11); break; //b
6643 case SCREENDATADOOR: GET_SCREENDATA_BYTE_INDEX(door, 3); break; //b, 4 of these
6644 case SCREENDATATILEWARPDMAP: GET_SCREENDATA_VAR_INDEX32(tilewarpdmap, 3); break; //w, 4 of these
6645 case SCREENDATATILEWARPSCREEN: GET_SCREENDATA_BYTE_INDEX(tilewarpscr, 3); break; //b, 4 of these
6646 case SCREENDATAEXITDIR: GET_SCREENDATA_VAR_BYTE(exitdir); break; //b
6647 case SCREENDATAENEMY: GET_SCREENDATA_VAR_INDEX32(enemy, 9); break; //w, 10 of these
6648 case SCREENDATAPATTERN: GET_SCREENDATA_VAR_BYTE(pattern); break; //b
6649 1124 case SCREENDATASIDEWARPTYPE: GET_SCREENDATA_BYTE_INDEX(sidewarptype, 3); break; //b, 4 of these
6650 //case SCREENDATASIDEWARPOVFLAGS: GET_SCREENDATA_VAR_BYTE(sidewarpoverlayflags); break; //b
6651 case SCREENDATAWARPARRIVALX: GET_SCREENDATA_VAR_BYTE(warparrivalx); break; //b
6652 case SCREENDATAWARPARRIVALY: GET_SCREENDATA_VAR_BYTE(warparrivaly); break; //b
6653 case SCREENDATAPATH: GET_SCREENDATA_BYTE_INDEX(path, 3); break; //b, 4 of these
6654 10 case SCREENDATASIDEWARPSC: GET_SCREENDATA_BYTE_INDEX(sidewarpscr, 3); break; //b, 4 of these
6655 152 case SCREENDATASIDEWARPDMAP: GET_SCREENDATA_VAR_INDEX32(sidewarpdmap, 3); break; //w, 4 of these
6656 case SCREENDATASIDEWARPINDEX: GET_SCREENDATA_VAR_BYTE(sidewarpindex); break; //b
6657 case SCREENDATAUNDERCOMBO: GET_SCREENDATA_VAR_INT32(undercombo); break; //w
6658 case SCREENDATAUNDERCSET: GET_SCREENDATA_VAR_BYTE(undercset); break; //b
6659 case SCREENDATACATCHALL: GET_SCREENDATA_VAR_INT32(catchall); break; //W
6660
6661 case SCREENDATACSENSITIVE: GET_SCREENDATA_VAR_BYTE(csensitive); break; //B
6662 case SCREENDATANORESET: GET_SCREENDATA_VAR_INT32(noreset); break; //W
6663 case SCREENDATANOCARRY: GET_SCREENDATA_VAR_INT32(nocarry); break; //W
6664
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
54 case SCREENDATALAYERMAP: GET_SCREENDATA_LAYER_INDEX(layermap, 6); break; //B, 6 OF THESE
6665 case SCREENDATALAYERSCREEN: GET_SCREENDATA_LAYER_INDEX(layerscreen, 6); break; //B, 6 OF THESE
6666 case SCREENDATALAYEROPACITY: GET_SCREENDATA_LAYER_INDEX(layeropacity, 6); break; //B, 6 OF THESE
6667 case SCREENDATALAYERINVIS:
6668 {
6669 int32_t indx = ri->d[rINDEX] / 10000;
6670 if(indx < 0 || indx > 6 )
6671 {
6672 scripting_log_error_with_context("Invalid index: {}", indx);
6673 ret = 0;
6674 }
6675 else
6676 {
6677 ret = ((get_scr(ri->screenref)->hidelayers >> indx) & 1) *10000;
6678 }
6679 break;
6680 }
6681 case SCREENDATASCRIPTDRAWS:
6682 {
6683 int32_t indx = ri->d[rINDEX] / 10000;
6684 if(indx < 0 || indx > 7 )
6685 {
6686 scripting_log_error_with_context("Invalid index: {}", indx);
6687 ret = 0;
6688 }
6689 else
6690 {
6691 ret = ((get_scr(ri->screenref)->hidescriptlayers >> indx) & 1) ? 0 : 10000;
6692 }
6693 break;
6694 }
6695 case SCREENDATATIMEDWARPTICS: GET_SCREENDATA_VAR_INT32(timedwarptics); break; //W
6696 case SCREENDATANEXTMAP: GET_SCREENDATA_VAR_BYTE(nextmap); break; //B
6697 case SCREENDATANEXTSCREEN: GET_SCREENDATA_VAR_BYTE(nextscr); break; //B
6698 109824 case SCREENDATASECRETCOMBO: GET_SCREENDATA_VAR_INDEX32(secretcombo, 127); break; //W, 128 OF THESE
6699 case SCREENDATASECRETCSET: GET_SCREENDATA_BYTE_INDEX(secretcset, 127); break; //B, 128 OF THESE
6700 case SCREENDATASECRETFLAG: GET_SCREENDATA_BYTE_INDEX(secretflag, 127); break; //B, 128 OF THESE
6701 case SCREENDATAVIEWX: break;//GET_SCREENDATA_VAR_INT32(viewX, "ViewX"); break; //W
6702 case SCREENDATAVIEWY: break;//GET_SCREENDATA_VAR_INT32(viewY, "ViewY"); break; //W
6703 case SCREENDATASCREENWIDTH: break;//GET_SCREENDATA_VAR_BYTE(scrWidth, "Width"); break; //B
6704 case SCREENDATASCREENHEIGHT: break;//GET_SCREENDATA_VAR_BYTE(scrHeight, "Height"); break; //B
6705 case SCREENDATAENTRYX: GET_SCREENDATA_VAR_BYTE(entry_x); break; //B
6706 case SCREENDATAENTRYY: GET_SCREENDATA_VAR_BYTE(entry_y); break; //B
6707 //Number of ffcs that are in use (have valid data
6708 // Note: that is totally not what its doing.
6709 case SCREENDATANUMFF:
6710 {
6711 int id = ri->d[rINDEX] / 10000;
6712 if (auto ffc = ResolveFFCWithID(id))
6713 ret = ffc->data != 0 ? 10000 : 0;
6714 break;
6715 }
6716
6717 case SCREENDATAFFINITIALISED: {
6718 int32_t indx = ri->d[rINDEX] / 10000;
6719 if (indx < 0 || indx > MAX_FFCID)
6720 {
6721 scripting_log_error_with_context("Invalid index: %d", (indx));
6722 ret = -10000;
6723 }
6724 else
6725 {
6726 ret = get_script_engine_data(ScriptType::FFC, indx).initialized ? 10000 : 0;
6727 }
6728 }
6729 break;
6730
6731 case SCREENDATASCRIPTENTRY:
6732 {
6733 Z_scripterrlog("Unimplemented: %s\n", "ScriptEntry");
6734 ret = -10000;
6735 }
6736 break;
6737 case SCREENDATASCRIPTOCCUPANCY:
6738 {
6739 Z_scripterrlog("Unimplemented: %s\n", "ScriptOccupancy");
6740 ret = -10000;
6741 }
6742 break;
6743 case SCREENDATASCRIPTEXIT:
6744 {
6745 Z_scripterrlog("Unimplemented: %s\n", "ExitScript");
6746 ret = -10000;
6747 }
6748 break;
6749
6750 case SCREENDATAOCEANSFX: GET_SCREENDATA_VAR_BYTE(oceansfx); break; //B
6751 case SCREENDATABOSSSFX: GET_SCREENDATA_VAR_BYTE(bosssfx); break; //B
6752 17 case SCREENDATASECRETSFX: GET_SCREENDATA_VAR_BYTE(secretsfx); break; //B
6753 case SCREENDATAHOLDUPSFX: GET_SCREENDATA_VAR_BYTE(holdupsfx); break; //B
6754 case SCREENDATASCREENMIDI:
6755 {
6756 ret = ((get_scr(ri->screenref)->screen_midi+(MIDIOFFSET_MAPSCR-MIDIOFFSET_ZSCRIPT)) *10000);
6757 break;
6758 }
6759 case SCREENDATALENSLAYER: GET_SCREENDATA_VAR_BYTE(lens_layer); break; //B, OLD QUESTS ONLY?
6760
6761 case SCREENSIDEWARPID:
6762 {
6763 2062 mapscr* scr = get_scr(ri->screenref);
6764 2062 int32_t indx = ri->d[rINDEX] / 10000;
6765
6766
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2062 times.
2062 if (BC::checkBounds(indx, 0, 3) != BC::_NoError)
6767 {
6768 ret = -10000;
6769 break;
6770 }
6771
6772
2/2
✓ Branch 0 taken 153 times.
✓ Branch 1 taken 1909 times.
2062 ret = (((scr->flags2 >> indx) & 1)
6773 153 ? (scr->sidewarpindex >> (2*indx)) & 3 //Return which warp is set
6774 : -1 //Returns -1 if no warp is set
6775 2062 )*10000;
6776 2062 break;
6777 }
6778
6779 case SCREENDATATILEWARPOVFLAGS:
6780 {
6781 int32_t indx = ri->d[rINDEX] / 10000;
6782 if ( ((unsigned)indx) > 3 )
6783 {
6784 Z_scripterrlog("Invalid index passed to TileWarpOverlayFlags[%d].\n. Valid indices are [0] through [3].\n", indx);
6785 ret = 0;
6786 }
6787 else
6788 {
6789 ret = (get_scr(ri->screenref)->tilewarpoverlayflags & (1<<indx))?10000:0;
6790 }
6791 break;
6792 }
6793
6794 case SCREENDATASIDEWARPOVFLAGS:
6795 {
6796 int32_t indx = ri->d[rINDEX] / 10000;
6797 if ( ((unsigned)indx) > 3 )
6798 {
6799 Z_scripterrlog("Invalid index passed to SideWarpOverlayFlags[%d].\n. Valid indices are [0] through [3].\n", indx);
6800 ret = 0;
6801 }
6802 else
6803 {
6804 ret = (get_scr(ri->screenref)->sidewarpoverlayflags & (1<<indx))?10000:0;
6805 }
6806 break;
6807 }
6808
6809 case SCREENDATATWARPRETSQR:
6810 {
6811 47 int32_t indx = ri->d[rINDEX] / 10000;
6812
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
47 if ( ((unsigned)indx) > 3)
6813 {
6814 ret = -10000;
6815 Z_scripterrlog("Invalid Array Index passed to Screen->TileWarpReturnSquare[]: %d\n", indx);
6816
6817 }
6818 else
6819 {
6820 47 ret = ((get_scr(ri->screenref)->warpreturnc>>(indx*2))&3) * 10000;
6821 }
6822 47 break;
6823 }
6824
6825
6826 case SCREENDATASWARPRETSQR:
6827 {
6828 3 int32_t indx = ri->d[rINDEX] / 10000;
6829
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if ( ((unsigned)indx) > 3)
6830 {
6831 ret = -10000;
6832 Z_scripterrlog("Invalid Array Index passed to Screen->SideWarpReturnSquare[]: %d\n", indx);
6833
6834 }
6835 else
6836 {
6837 3 ret = ((get_scr(ri->screenref)->warpreturnc>>(8+(indx*2)))&3) * 10000;
6838 }
6839 3 break;
6840 }
6841
6842 case SCREENDATAFLAGS:
6843 {
6844 mapscr* scr = get_scr(ri->screenref);
6845 int32_t flagid = (ri->d[rINDEX])/10000;
6846 //bool valtrue = ( value ? 10000 : 0);
6847 switch(flagid)
6848 {
6849 case 0: ret = (scr->flags * 10000); break;
6850 case 1: ret = (scr->flags2 * 10000); break;
6851 case 2: ret = (scr->flags3 * 10000); break;
6852 case 3: ret = (scr->flags4 * 10000); break;
6853 case 4: ret = (scr->flags5 * 10000); break;
6854 case 5: ret = (scr->flags6 * 10000); break;
6855 case 6: ret = (scr->flags7 * 10000); break;
6856 case 7: ret = (scr->flags8 * 10000); break;
6857 case 8: ret = (scr->flags9 * 10000); break;
6858 case 9: ret = (scr->flags10 * 10000); break;
6859 case 10: ret = (scr->flags11 * 10000); break;
6860 default:
6861 {
6862 Z_scripterrlog("Invalid index passed to mapdata->flags[]: %d\n", flagid);
6863 ret = -10000;
6864 break;
6865
6866 }
6867 }
6868 break;
6869 }
6870
6871 case SCREENSECRETSTRIGGERED:
6872 {
6873 910 ret = get_screen_state(ri->screenref).triggered_secrets ? 10000L : 0L;
6874 910 break;
6875 }
6876
6877 case SCREENDATAGUYCOUNT:
6878 {
6879 int mi = mapind(cur_map, ri->screenref);
6880 if(mi < 0)
6881 ret = -10000;
6882 else ret = game->guys[mi] * 10000;
6883 break;
6884 }
6885 case SCREENDATAEXDOOR:
6886 {
6887 ret = 0;
6888 int mi = mapind(cur_map, ri->screenref);
6889 if(mi < 0) break;
6890 int dir = SH::read_stack(ri->sp+1) / 10000;
6891 int ind = SH::read_stack(ri->sp+0) / 10000;
6892 if(unsigned(dir) > 3)
6893 Z_scripterrlog("Invalid dir '%d' passed to 'Screen->GetExDoor()'; must be 0-3\n", dir);
6894 else if(unsigned(ind) > 7)
6895 Z_scripterrlog("Invalid index '%d' passed to 'Screen->GetExDoor()'; must be 0-7\n", ind);
6896 else
6897 {
6898 int bit = 1<<ind;
6899 ret = (game->xdoors[mi][dir]&bit) ? 10000 : 0;
6900 }
6901 break;
6902 }
6903
6904 case SHOWNMSG:
6905 {
6906
4/4
✓ Branch 0 taken 1832 times.
✓ Branch 1 taken 7660 times.
✓ Branch 2 taken 1800 times.
✓ Branch 3 taken 32 times.
9492 ret = ((msg_active || msg_onscreen) ? msgstr : 0) * 10000L;
6907 9492 break;
6908 }
6909
6910 case SDD:
6911 {
6912
2/2
✓ Branch 0 taken 1872829 times.
✓ Branch 1 taken 701546 times.
2574375 int32_t di = ((get_currdmap())<<7) + get_currscr()-(DMaps[get_currdmap()].type==dmOVERW ? 0 : DMaps[get_currdmap()].xoff);
6913 2574375 ret=FFScript::get_screen_d(di, ri->d[rINDEX]/10000);
6914 }
6915 2574375 break;
6916
6917 case SDDD:
6918 43250 ret=FFScript::get_screen_d((ri->d[rINDEX])/10000 + ((get_currdmap())<<7), ri->d[rINDEX2] / 10000);
6919 43250 break;
6920
6921 case LINKOTILE:
6922 ret=FFCore.getHeroOTile(ri->d[rINDEX]/10000, ri->d[rINDEX2] / 10000);
6923 break;
6924
6925 case SDDDD:
6926 6 ret=FFScript::get_screen_d(ri->d[rINDEX2] / 10000 + ((ri->d[rINDEX]/10000)<<7), ri->d[rEXP1] / 10000);
6927 6 break;
6928
6929 case SCRDOORD:
6930 4 ret = read_array(get_scr(ri->screenref)->door, ri->d[rINDEX]/10000) * 10000;
6931 4 break;
6932
6933 case SCREENSCRIPT:
6934 ret=get_scr(ri->screenref)->script*10000;
6935 break;
6936
6937 case SCREENINITD:
6938 ret = read_array(get_scr(ri->screenref)->screeninitd, ri->d[rINDEX]/10000);
6939 break;
6940
6941 case MAPDATAINITDARRAY:
6942 {
6943 if (auto scr = ResolveMapdata(ri->mapsref))
6944 ret = read_array(scr->screeninitd, ri->d[rINDEX]/10000);
6945 break;
6946 }
6947
6948 case MAPDATALAYERINVIS:
6949 {
6950 int32_t indx = ri->d[rINDEX] / 10000;
6951 if(indx < 0 || indx > 6 )
6952 {
6953 scripting_log_error_with_context("Invalid index: {}", indx);
6954 ret = 0;
6955 }
6956 else
6957 {
6958 mapscr *m = ResolveMapdata(ri->mapsref);
6959 if ( !m )
6960 {
6961 ret = -10000;
6962 }
6963 else
6964 {
6965 ret = ((m->hidelayers >> indx) & 1) *10000;
6966 }
6967 }
6968 break;
6969 }
6970 case MAPDATASCRIPTDRAWS:
6971 {
6972 int32_t indx = ri->d[rINDEX] / 10000;
6973 if(indx < 0 || indx > 7 )
6974 {
6975 Z_scripterrlog("Invalid Index passed to mapdata->DisableScriptDraws[]: %d\n", indx);
6976 ret = 0;
6977 }
6978 else
6979 {
6980 mapscr *m = ResolveMapdata(ri->mapsref);
6981 if ( !m )
6982 {
6983 ret = -10000;
6984 }
6985 else
6986 {
6987 ret = ((m->hidescriptlayers >> indx) & 1) ? 0 : 10000;
6988 }
6989 }
6990 break;
6991 }
6992
6993 //These use the same method as GetScreenD -Z
6994 case SCREENWIDTH:
6995 // ret=FFScript::get_screenWidth(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)]);
6996 break;
6997
6998 case SCREENHEIGHT:
6999 // ret=FFScript::get_screenHeight(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)]);
7000 break;
7001
7002 case SCREENVIEWX:
7003 // ret=get_screenViewX(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)]);
7004 break;
7005
7006 case SCREENVIEWY:
7007 // ret=get_screenViewY(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)]);
7008 break;
7009
7010 case LIT:
7011 10246 ret= get_lights() ? 10000 : 0;
7012 10246 break;
7013
7014 case WAVY:
7015 7214 ret = wavy*10000;
7016 7214 break;
7017
7018 case QUAKE:
7019 2391 ret = quakeclk*10000;
7020 2391 break;
7021
7022 case SCREENFLAGSD:
7023 11161012 ret = get_screenflags(get_scr(ri->screenref),vbound(ri->d[rINDEX] / 10000,0,9));
7024 11161012 break;
7025
7026 case SCREENEFLAGSD:
7027 4473523 ret = get_screeneflags(get_scr(ri->screenref),vbound(ri->d[rINDEX] / 10000,0,2));
7028 4473523 break;
7029
7030 case SCREEN_FLAG:
7031 {
7032 704596 int32_t index = ri->d[rINDEX] / 10000;
7033
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 704596 times.
704596 if (BC::checkIndex(index, 0, 8*11 - 1) != SH::_NoError)
7034 {
7035 ret = 0;
7036 break;
7037 }
7038
7039 704596 mapscr* scr = get_scr(ri->screenref);
7040 704596 ret = (&scr->flags)[index/8] & (1 << (index%8)) ? 10000 : 0;
7041 704596 break;
7042 }
7043
7044 case NPCCOUNT:
7045 25369203 ret = guys.Count()*10000;
7046 25369203 break;
7047
7048 case ROOMDATA:
7049 47 ret = get_scr(ri->screenref)->catchall*10000;
7050 47 break;
7051
7052 case ROOMTYPE:
7053 2 ret = get_scr(ri->screenref)->room*10000;
7054 2 break;
7055
7056 case PUSHBLOCKX:
7057
2/2
✓ Branch 0 taken 3584 times.
✓ Branch 1 taken 339575 times.
343159 ret = mblock2.active() ? int32_t(mblock2.x)*10000 : -10000;
7058 343159 break;
7059
7060 case PUSHBLOCKY:
7061
2/2
✓ Branch 0 taken 2943 times.
✓ Branch 1 taken 98007 times.
100950 ret = mblock2.active() ? int32_t(mblock2.y)*10000 : -10000;
7062 100950 break;
7063
7064 case PUSHBLOCKLAYER:
7065 ret = mblock2.active() ? int32_t(mblock2.blockLayer)*10000 : -10000;
7066 break;
7067
7068 case PUSHBLOCKCOMBO:
7069 ret = mblock2.bcombo*10000;
7070 break;
7071
7072 case PUSHBLOCKCSET:
7073 ret = mblock2.cs*10000;
7074 break;
7075
7076 case UNDERCOMBO:
7077 1636 ret = get_scr(ri->screenref)->undercombo*10000;
7078 1636 break;
7079
7080 case UNDERCSET:
7081 1610 ret = get_scr(ri->screenref)->undercset*10000;
7082 1610 break;
7083
7084 case SCREEN_INDEX:
7085 32 ret = ri->screenref*10000;
7086 32 break;
7087
7088 case SCREEN_DRAW_ORIGIN:
7089 ret = (int)ri->screen_draw_origin;
7090 break;
7091
7092 case SCREEN_DRAW_ORIGIN_TARGET:
7093 ret = ri->screen_draw_origin_target;
7094 break;
7095
7096 //Creates an lweapon using an iemdata struct values to generate its properties.
7097 //Useful in conjunction with the new weapon editor.
7098 case CREATELWPNDX:
7099 {
7100 //Z_message("Trying to get Hero->SetExtend().\n");
7101 int32_t ID = (ri->d[rINDEX] / 10000);
7102 int32_t itemid = (ri->d[rINDEX2]/10000);
7103 itemid = vbound(itemid,0,(MAXITEMS-1));
7104
7105 // TODO: use has_space()
7106 if ( Lwpns.Count() < 256 )
7107 {
7108
7109 (void)Lwpns.add
7110 (
7111 new weapon
7112 (
7113 (zfix)0, /*X*/
7114 (zfix)0, /*Y*/
7115 (zfix)0, /*Z*/
7116 ID, /*id*/
7117 0, /*type*/
7118 0, /*power*/
7119 0, /*dir*/
7120 -1, /*Parentid*/
7121 Hero.getUID(), /*prntid*/
7122 false, /*isdummy*/
7123 1, /*script_gen*/
7124 1, /*islwpn*/
7125 (ID==wWind?1:0) /*special*/
7126 )
7127 );
7128 ri->lwpn = Lwpns.spr(Lwpns.Count() - 1)->getUID();
7129
7130 weapon *w = (weapon*)Lwpns.spr(Lwpns.Count()-1); //last created
7131 //w->LOADGFX(FFCore.getDefWeaponSprite(ID)); //What the fuck Zoria, this broke old quests...
7132 w->ScriptGenerated = 1;
7133 w->isLWeapon = 1;
7134 if(ID == wWind) w->specialinfo = 1;
7135 //weapon *w = (weapon*)Lwpns.spr(Lwpns.Count()-1); //last created
7136 //w->LOADGFX(FFCore.getDefWeaponSprite(ID)); //not needed here because this has access to wpn->prent
7137 }
7138 else
7139 {
7140 Z_scripterrlog("Tried to create too many LWeapons on the screen. The current LWeapon count is: %d\n", Lwpns.Count());
7141 ri->lwpn = 0;
7142 }
7143
7144 /* Z_scripterrlog("CreateLWeaponDx ri->d[rINDEX] is (%i), trying to use for '%s'\n", ID, "ID");
7145 Z_scripterrlog("CreateLWeaponDx ri->d[rINDEX2] is (%i), trying to use for '%s'\n", itemid, "itemid");
7146 Z_scripterrlog("CreateLWeaponDx ri->lwpn is (%i), trying to use for '%s'\n", ri->lwpn, "ri->lwpn"); */
7147
7148 ret = ri->lwpn;
7149 }
7150 break;
7151
7152 /*
7153 //Screen->CollisionDx(int32_t enemy_index, int32_t lweapon_type, int32_t power, int32_t x, int32_t y, int32_t weapon_dir, int32_t parent_item);
7154 //Handles collision between an npc at screen index 'enemy_index', and an arbitrary lweapon that may or may not exist.
7155 //Does damage, and returns true a value collision is valid. Returns a different value otherwise.
7156
7157 // take damage or ignore it
7158 // -1: damage (if any) dealt
7159 // 1: blocked
7160 // 0: weapon passes through unhindered
7161 // 2: heal enemy? -ZoriaRPG
7162
7163 //THis function should automatically check for shields blocking the weapon, and calculate enemy defences.
7164 //In theory, scritped swords, and other melee weapons could use this, as coudl any weapon, and it may simplify
7165 //collision routines.
7166 case COLLISIONDX:
7167 {
7168 //Z_message("Trying to get Hero->SetExtend().\n");
7169 int32_t index = (ri->d[rINDEX] / 10000);
7170 int32_t lweapon_type = (ri->d[rINDEX2] / 10000);
7171 int32_t power = (ri->d[rEXP1]/10000);
7172
7173 int32_t wpnx = ri->4[3]/10000, wpny = ri->d[rSFRAME]/10000;
7174 int32_t dir = ri->d[rNUL]/10000;
7175 int32_t parentitem = (ri->d[rSFTEMP]/10000);
7176 lweapon_type = vbound(lweapon_type,0,40); //Are we at 40, or higher now>
7177 parentitem = vbound(itemid,0,255);
7178
7179 //Log the stack events:
7180 Z_scripterrlog("CollisionDx ri->d[rINDEX] is (%i), trying to use for '%s'\n", index, "index");
7181 Z_scripterrlog("CollisionDx ri->d[rINDEX2] is (%i), trying to use for '%s'\n", lweapon_type, "lweapon_type");
7182 Z_scripterrlog("CollisionDx ri->d[rEXP1] is (%i), trying to use for '%s'\n", power, "power");
7183 Z_scripterrlog("CollisionDx ri->d[rEXP2] is (%i), trying to use for '%s'\n", wpnx, "wpnx");
7184 Z_scripterrlog("CollisionDx ri->d[rSFRAME] is (%i), trying to use for '%s'\n", wpny, "wpny");
7185 Z_scripterrlog("CollisionDx ri->d[rNUL] is (%i), trying to use for '%s'\n", dir, "dir");
7186 Z_scripterrlog("CollisionDx ri->d[rINDEX] is (%i), trying to use for '%s'\n", parentitem, "parentitem");
7187
7188 weapon *w = new weapon((zfix)wpnx,(zfix)wpny,(zfix)0,lweapon_type,0,power,dir,parentitem,-1,false);
7189 int32_t retval = ((enemy*)guys.spr(index))->takehit(w);
7190 //TakeHit, as I recall, applies damage and returns the hit status. Gold.
7191 delete w;
7192 ret = retval;
7193 }
7194 break;
7195
7196 */
7197 case DEBUGREFFFC:
7198 {
7199 int32_t r = -1;
7200 if ( ri->ffcref ) r = ri->ffcref;
7201 ret = r * 10000;
7202 break;
7203 }
7204
7205 case DEBUGREFITEM:
7206 {
7207 int32_t r = -1;
7208 if ( ri->itemref ) r = ri->itemref;
7209 ret = r * 10000;
7210 break;
7211 }
7212
7213 case DEBUGREFITEMDATA:
7214 {
7215 int32_t r = -1;
7216 if ( ri->idata ) r = ri->idata;
7217 ret = r * 10000;
7218 break;
7219 }
7220
7221 case DEBUGREFLWEAPON:
7222 {
7223 int32_t r = -1;
7224 if ( ri->lwpn ) r = ri->lwpn;
7225 ret = r * 10000;
7226 break;
7227 }
7228
7229 case DEBUGREFEWEAPON:
7230 {
7231 int32_t r = -1;
7232 if ( ri->ewpn ) r = ri->ewpn;
7233 ret = r * 10000;
7234 break;
7235 }
7236
7237 case DEBUGREFNPC:
7238 {
7239 int32_t r = -1;
7240 if ( ri->guyref ) r = ri->guyref;
7241 ret = r * 10000;
7242 break;
7243 }
7244
7245 case DEBUGSP:
7246 {
7247 ret = SH::read_stack(ri->sp) * 10000;
7248 break;
7249 }
7250 case DEBUGGDR:
7251 {
7252 int32_t a = vbound(ri->d[rINDEX]/10000,0,15);
7253 int32_t r = -1;
7254 if ( game->global_d[a] ) r = game->global_d[a];
7255 ret = r * 10000;
7256 break;
7257 }
7258
7259 ///----------------------------------------------------------------------------------------------------//
7260 //New Datatype Variables
7261
7262 ///----------------------------------------------------------------------------------------------------//
7263 //spritedata sp-> Variables
7264
7265
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 case SPRITEDATATILE: GET_SPRITEDATA_VAR_INT(tile) break;
7266 case SPRITEDATAMISC: GET_SPRITEDATA_VAR_INT(misc) break;
7267 case SPRITEDATACSETS:
7268 {
7269
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if(unsigned(ri->spritedataref) > (MAXWPNS-1) )
7270 {
7271 ret = -10000;
7272 Z_scripterrlog("Invalid Sprite ID passed to spritedata->CSet: %d\n", (ri->spritedataref*10000));
7273 }
7274 else
7275 16 ret = ((wpnsbuf[ri->spritedataref].csets & 0xF) * 10000);
7276 16 break;
7277 }
7278 case SPRITEDATAFLCSET:
7279 {
7280 if(unsigned(ri->spritedataref) > (MAXWPNS-1) )
7281 {
7282 ret = -10000;
7283 Z_scripterrlog("Invalid Sprite ID passed to spritedata->%s: %d\n", (ri->spritedataref*10000), "FlashCSet");
7284 break;
7285 }
7286 ret = (((wpnsbuf[ri->spritedataref].csets & 0xF0)>>4) * 10000);
7287 break;
7288 }
7289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 case SPRITEDATAFRAMES: GET_SPRITEDATA_VAR_INT(frames) break;
7290
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 case SPRITEDATASPEED: GET_SPRITEDATA_VAR_INT(speed) break;
7291 case SPRITEDATATYPE: GET_SPRITEDATA_VAR_INT(type) break;
7292 case SPRITEDATAFLAGS:
7293 {
7294 if(unsigned(ri->spritedataref) > (MAXWPNS-1) )
7295 {
7296 ret = 0;
7297 Z_scripterrlog("Invalid Sprite ID passed to spritedata->Flags[]: %d\n", (ri->spritedataref*10000));
7298 break;
7299 }
7300 int32_t index = ri->d[rINDEX]/10000;
7301 if(unsigned(index) >= 5)
7302 {
7303 ret = 0;
7304 Z_scripterrlog("Invalid index passed to spritedata->Flags[]: %d\n", index);
7305 break;
7306 }
7307 ret = (wpnsbuf[ri->spritedataref].misc & (1<<index)) ? 10000 : 0;
7308 break;
7309 }
7310 case SPRITEDATAID:
7311 {
7312 if(unsigned(ri->spritedataref) > (MAXWPNS-1) )
7313 {
7314 ret = -10000;
7315 Z_scripterrlog("Invalid Sprite ID passed to spritedata->ID: %d\n", (ri->spritedataref*10000));
7316 break;
7317 }
7318 ret = ri->spritedataref*10000;
7319 break;
7320 }
7321
7322 ///----------------------------------------------------------------------------------------------------//
7323 //mapdata m-> variables
7324 #define GET_MAPDATA_VAR_INT32(member) \
7325 { \
7326 if ( mapscr *m = ResolveMapdata(ri->mapsref) ) \
7327 { \
7328 ret = (m->member *10000); \
7329 } \
7330 else \
7331 { \
7332 ret = -10000; \
7333 } \
7334 } \
7335
7336 #define GET_MAPDATA_VAR_INT16(member) \
7337 { \
7338 if ( mapscr *m = ResolveMapdata(ri->mapsref) ) \
7339 { \
7340 ret = (m->member *10000); \
7341 } \
7342 else \
7343 { \
7344 ret = -10000; \
7345 } \
7346 } \
7347
7348 #define GET_MAPDATA_VAR_BYTE(member) \
7349 { \
7350 if ( mapscr *m = ResolveMapdata(ri->mapsref) ) \
7351 { \
7352 ret = (m->member *10000); \
7353 } \
7354 else \
7355 { \
7356 ret = -10000; \
7357 } \
7358 } \
7359
7360 #define GET_MAPDATA_VAR_INDEX32(member, indexbound) \
7361 { \
7362 int32_t indx = ri->d[rINDEX] / 10000; \
7363 if (BC::checkIndex(indx, 0, indexbound) != SH::_NoError) \
7364 { \
7365 ret = -10000; \
7366 } \
7367 else \
7368 { \
7369 if (mapscr *m = ResolveMapdata(ri->mapsref)) \
7370 { \
7371 ret = (m->member[indx] *10000); \
7372 } \
7373 else \
7374 { \
7375 ret = -10000; \
7376 } \
7377 } \
7378 } \
7379
7380 #define GET_MAPDATA_VAR_INDEX16(member, indexbound) \
7381 { \
7382 int32_t indx = ri->d[rINDEX] / 10000; \
7383 if (BC::checkIndex(indx, 0, indexbound) != SH::_NoError) \
7384 { \
7385 ret = -10000; \
7386 } \
7387 else \
7388 { \
7389 if (mapscr *m = ResolveMapdata(ri->mapsref)) \
7390 { \
7391 ret = (m->member[indx] *10000); \
7392 } \
7393 else \
7394 { \
7395 ret = -10000; \
7396 } \
7397 } \
7398 } \
7399
7400 #define GET_MAPDATA_BYTE_INDEX(member, indexbound) \
7401 { \
7402 int32_t indx = ri->d[rINDEX] / 10000; \
7403 if (BC::checkIndex(indx, 0, indexbound) != SH::_NoError) \
7404 { \
7405 ret = -10000; \
7406 } \
7407 else \
7408 { \
7409 if (mapscr *m = ResolveMapdata(ri->mapsref)) \
7410 { \
7411 ret = (m->member[indx] *10000); \
7412 } \
7413 else \
7414 { \
7415 ret = -10000; \
7416 } \
7417 } \
7418 } \
7419
7420 #define GET_MAPDATA_LAYER_INDEX(member, indexbound) \
7421 { \
7422 int32_t indx = ri->d[rINDEX] / 10000; \
7423 if ( FFCore.quest_format[vFFScript] < 11 ) ++indx; \
7424 if (BC::checkIndex(indx, 1, indexbound) != SH::_NoError) \
7425 { \
7426 ret = -10000; \
7427 } \
7428 else \
7429 { \
7430 if (mapscr *m = ResolveMapdata(ri->mapsref)) \
7431 { \
7432 ret = (m->member[indx-1] *10000); \
7433 } \
7434 else \
7435 { \
7436 ret = -10000; \
7437 } \
7438 } \
7439 } \
7440
7441 #define GET_MAPDATA_BOOL_INDEX(member, indexbound) \
7442 { \
7443 int32_t indx = ri->d[rINDEX] / 10000; \
7444 if (BC::checkIndex(indx, 0, indexbound) != SH::_NoError) \
7445 { \
7446 ret = -10000; \
7447 } \
7448 else \
7449 { \
7450 if (mapscr *m = ResolveMapdata(ri->mapsref)) \
7451 { \
7452 ret = (m->member[indx]?10000:0); \
7453 } \
7454 else \
7455 { \
7456 ret = -10000; \
7457 } \
7458 } \
7459 } \
7460
7461 #define GET_MAPDATA_FLAG(member) \
7462 { \
7463 int32_t flag = (value/10000); \
7464 if (mapscr *m = ResolveMapdata(ri->mapsref)) \
7465 { \
7466 ret = (m->member&flag) ? 10000 : 0); \
7467 } \
7468 else \
7469 { \
7470 ret = -10000; \
7471 } \
7472 } \
7473
7474 #define GET_MAPDATA_FFCPOS_INDEX32(member, indexbound) \
7475 { \
7476 int32_t index = (ri->d[rINDEX] / 10000); \
7477 if (auto handle = ResolveMapdataFFC(ri->mapsref, index)) \
7478 { \
7479 ret = (handle.ffc->member).getZLong(); \
7480 } \
7481 else \
7482 { \
7483 ret = -10000; \
7484 } \
7485 } \
7486
7487 #define GET_MAPDATA_FFC_INDEX32(member, indexbound) \
7488 { \
7489 int32_t index = (ri->d[rINDEX] / 10000); \
7490 if (auto handle = ResolveMapdataFFC(ri->mapsref, index)) \
7491 { \
7492 ret = (handle.ffc->member)*10000; \
7493 } \
7494 else \
7495 { \
7496 ret = -10000; \
7497 } \
7498 } \
7499
7500 #define GET_MAPDATA_FFC_INDEX32(member, indexbound) \
7501 { \
7502 int32_t index = (ri->d[rINDEX] / 10000); \
7503 if (auto handle = ResolveMapdataFFC(ri->mapsref, index)) \
7504 { \
7505 ret = (handle.ffc->member)*10000; \
7506 } \
7507 else \
7508 { \
7509 ret = -10000; \
7510 } \
7511 } \
7512
7513 case LOADMAPDATA:
7514 6567187 ret=FFScript::loadMapData();
7515 6567187 break;
7516
7517 case CREATEBITMAP:
7518 {
7519 3856 ret=FFCore.do_create_bitmap();
7520 3856 break;
7521 }
7522
7523
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 case MAPDATAVALID: GET_MAPDATA_VAR_BYTE(valid); break; //b
7524 case MAPDATAGUY: GET_MAPDATA_VAR_BYTE(guy); break; //b
7525 case MAPDATASTRING: GET_MAPDATA_VAR_INT32(str); break; //w
7526 case MAPDATAROOM: GET_MAPDATA_VAR_BYTE(room); break; //b
7527 case MAPDATAITEM:
7528 {
7529 if ( mapscr *m = ResolveMapdata(ri->mapsref) )
7530 {
7531 if(m->hasitem)
7532 ret = (m->item *10000);
7533 else ret = -10000;
7534 }
7535 else
7536 {
7537 ret = -10000;
7538 }
7539 break;
7540 }
7541 case MAPDATAREGIONID:
7542 {
7543 if (auto scr = ResolveMapdata(ri->mapsref))
7544 ret = get_region_id(scr->map, scr->screen) * 10000;
7545 break;
7546 }
7547 case MAPDATAHASITEM: GET_MAPDATA_VAR_BYTE(hasitem); break; //b
7548 case MAPDATATILEWARPTYPE: GET_MAPDATA_BYTE_INDEX(tilewarptype, 3); break; //b, 4 of these
7549 //case MAPDATATILEWARPOVFLAGS: GET_MAPDATA_VAR_BYTE(tilewarpoverlayflags); break; //b, tilewarpoverlayflags
7550 case MAPDATADOORCOMBOSET: GET_MAPDATA_VAR_INT32(door_combo_set); break; //w
7551 case MAPDATAWARPRETX: GET_MAPDATA_BYTE_INDEX(warpreturnx, 3); break; //b, 4 of these
7552 case MAPDATAWARPRETY: GET_MAPDATA_BYTE_INDEX(warpreturny, 3); break; //b, 4 of these
7553 case MAPDATAWARPRETURNC: GET_MAPDATA_VAR_INT32(warpreturnc); break; //w
7554 case MAPDATASTAIRX: GET_MAPDATA_VAR_BYTE(stairx); break; //b
7555 case MAPDATASTAIRY: GET_MAPDATA_VAR_BYTE(stairy); break; //b
7556 case MAPDATAITEMX: GET_MAPDATA_VAR_BYTE(itemx); break; //itemx
7557 case MAPDATAITEMY: GET_MAPDATA_VAR_BYTE(itemy); break; //itemy
7558
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 192 times.
192 case MAPDATACOLOUR: GET_MAPDATA_VAR_INT32(color); break; //w
7559 case MAPDATAENEMYFLAGS: GET_MAPDATA_VAR_BYTE(flags11); break; //b
7560 case MAPDATADOOR: GET_MAPDATA_BYTE_INDEX(door, 3); break; //b, 4 of these
7561 case MAPDATATILEWARPDMAP: GET_MAPDATA_VAR_INDEX32(tilewarpdmap, 3); break; //w, 4 of these
7562 case MAPDATATILEWARPSCREEN: GET_MAPDATA_BYTE_INDEX(tilewarpscr, 3); break; //b, 4 of these
7563 case MAPDATAEXITDIR: GET_MAPDATA_VAR_BYTE(exitdir); break; //b
7564 case MAPDATAENEMY: GET_MAPDATA_VAR_INDEX32(enemy, 9); break; //w, 10 of these
7565 case MAPDATAPATTERN: GET_MAPDATA_VAR_BYTE(pattern); break; //b
7566 case MAPDATASIDEWARPTYPE: GET_MAPDATA_BYTE_INDEX(sidewarptype, 3); break; //b, 4 of these
7567 //case MAPDATASIDEWARPOVFLAGS: GET_MAPDATA_VAR_BYTE(sidewarpoverlayflags); break; //b
7568 case MAPDATAWARPARRIVALX: GET_MAPDATA_VAR_BYTE(warparrivalx); break; //b
7569 case MAPDATAWARPARRIVALY: GET_MAPDATA_VAR_BYTE(warparrivaly); break; //b
7570 case MAPDATAPATH: GET_MAPDATA_BYTE_INDEX(path, 3); break; //b, 4 of these
7571 case MAPDATASIDEWARPSC: GET_MAPDATA_BYTE_INDEX(sidewarpscr, 3); break; //b, 4 of these
7572 case MAPDATASIDEWARPDMAP: GET_MAPDATA_VAR_INDEX32(sidewarpdmap, 3); break; //w, 4 of these
7573 case MAPDATASIDEWARPINDEX: GET_MAPDATA_VAR_BYTE(sidewarpindex); break; //b
7574 case MAPDATAUNDERCOMBO: GET_MAPDATA_VAR_INT32(undercombo); break; //w
7575 case MAPDATAUNDERCSET: GET_MAPDATA_VAR_BYTE(undercset); break; //b
7576 case MAPDATACATCHALL: GET_MAPDATA_VAR_INT32(catchall); break; //W
7577
7578 case MAPDATACSENSITIVE: GET_MAPDATA_VAR_BYTE(csensitive); break; //B
7579 case MAPDATANORESET: GET_MAPDATA_VAR_INT32(noreset); break; //W
7580 case MAPDATANOCARRY: GET_MAPDATA_VAR_INT32(nocarry); break; //W
7581
3/6
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
✓ Branch 4 taken 13 times.
✗ Branch 5 not taken.
26 case MAPDATALAYERMAP: GET_MAPDATA_LAYER_INDEX(layermap, 6); break; //B, 6 OF THESE
7582
3/6
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
✓ Branch 4 taken 13 times.
✗ Branch 5 not taken.
26 case MAPDATALAYERSCREEN: GET_MAPDATA_LAYER_INDEX(layerscreen, 6); break; //B, 6 OF THESE
7583 case MAPDATALAYEROPACITY: GET_MAPDATA_LAYER_INDEX(layeropacity, 6); break; //B, 6 OF THESE
7584 case MAPDATATIMEDWARPTICS: GET_MAPDATA_VAR_INT32(timedwarptics); break; //W
7585 case MAPDATANEXTMAP: GET_MAPDATA_VAR_BYTE(nextmap); break; //B
7586 case MAPDATANEXTSCREEN: GET_MAPDATA_VAR_BYTE(nextscr); break; //B
7587
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 128 times.
✗ Branch 3 not taken.
256 case MAPDATASECRETCOMBO: GET_MAPDATA_VAR_INDEX32(secretcombo, 127); break; //W, 128 OF THESE
7588
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 128 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 128 times.
256 case MAPDATASECRETCSET: GET_MAPDATA_BYTE_INDEX(secretcset, 127); break; //B, 128 OF THESE
7589
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 128 times.
✗ Branch 3 not taken.
256 case MAPDATASECRETFLAG: GET_MAPDATA_BYTE_INDEX(secretflag, 127); break; //B, 128 OF THESE
7590
7591 case MAPDATAVIEWX: break;//GET_MAPDATA_VAR_INT32(viewX, "ViewX"); break; //W
7592 case MAPDATASCRIPT: GET_MAPDATA_VAR_INT32(script); break; //W
7593 case MAPDATAVIEWY: break;//GET_MAPDATA_VAR_INT32(viewY, "ViewY"); break; //W
7594 case MAPDATASCREENWIDTH: break;//GET_MAPDATA_VAR_BYTE(scrWidth, "Width"); break; //B
7595 case MAPDATASCREENHEIGHT: break;//GET_MAPDATA_VAR_BYTE(scrHeight, "Height"); break; //B
7596 case MAPDATAENTRYX: GET_MAPDATA_VAR_BYTE(entry_x); break; //B
7597 case MAPDATAENTRYY: GET_MAPDATA_VAR_BYTE(entry_y); break; //B
7598
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 case MAPDATAFFDATA: GET_MAPDATA_FFC_INDEX32(data, MAXFFCS-1); break; //W, MAXFFCS OF THESE
7599
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 case MAPDATAFFCSET: GET_MAPDATA_FFC_INDEX32(cset, MAXFFCS-1); break; //B, MAXFFCS
7600
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 case MAPDATAFFDELAY: GET_MAPDATA_FFC_INDEX32(delay, MAXFFCS-1); break; //W, MAXFFCS
7601
1/2
✓ Branch 0 taken 392 times.
✗ Branch 1 not taken.
392 case MAPDATAFFX: GET_MAPDATA_FFCPOS_INDEX32(x, MAXFFCS-1); break; //INT32, MAXFFCS OF THESE
7602
1/2
✓ Branch 0 taken 392 times.
✗ Branch 1 not taken.
392 case MAPDATAFFY: GET_MAPDATA_FFCPOS_INDEX32(y, MAXFFCS-1); break; //..
7603
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 case MAPDATAFFXDELTA: GET_MAPDATA_FFCPOS_INDEX32(vx, MAXFFCS-1); break; //..
7604
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 case MAPDATAFFYDELTA: GET_MAPDATA_FFCPOS_INDEX32(vy, MAXFFCS-1); break; //..
7605
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 case MAPDATAFFXDELTA2: GET_MAPDATA_FFCPOS_INDEX32(ax, MAXFFCS-1); break; //..
7606
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 case MAPDATAFFYDELTA2: GET_MAPDATA_FFCPOS_INDEX32(ay, MAXFFCS-1); break; //..
7607
1/2
✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
91 case MAPDATAFFFLAGS: GET_MAPDATA_FFC_INDEX32(flags, MAXFFCS-1); break; //INT16, MAXFFCS OF THESE
7608 case MAPDATASIDEWARPID:
7609 {
7610 int32_t indx = ri->d[rINDEX] / 10000;
7611 if (mapscr *m = ResolveMapdata(ri->mapsref); m && BC::checkBounds(indx, 0, 3) == BC::_NoError)
7612 {
7613 ret = (((m->flags2 >> indx) & 1)
7614 ? (m->sidewarpindex >> (2*indx)) & 3 //Return which warp is set
7615 : -1 //Returns -1 if no warp is set
7616 )*10000;
7617 }
7618 else
7619 {
7620 ret = -10000;
7621 }
7622 break;
7623 }
7624 //Number of ffcs that are in use (have valid data
7625 case MAPDATANUMFF:
7626 {
7627 32 int index = ri->d[rINDEX] / 10000;
7628
7629
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 if (auto handle = ResolveMapdataFFC(ri->mapsref, index))
7630 {
7631 32 ret = (handle.data() != 0) ? 10000 : 0;
7632 32 }
7633 else
7634 {
7635 ret = 0;
7636 }
7637 32 break;
7638 }
7639
7640 case MAPDATATILEWARPOVFLAGS:
7641 {
7642 int32_t indx = ri->d[rINDEX] / 10000;
7643 if ( ((unsigned)indx) > 3 )
7644 {
7645 Z_scripterrlog("Invalid index passed to TileWarpOverlayFlags[%d].\n. Valid indices are [0] through [3].\n", indx);
7646 ret = 0;
7647 }
7648 else if (mapscr *m = ResolveMapdata(ri->mapsref))
7649 {
7650 ret = (m->tilewarpoverlayflags & (1<<indx))?10000:0;
7651 }
7652 else
7653 {
7654 ret = 0;
7655 }
7656 break;
7657 }
7658
7659 case MAPDATASIDEWARPOVFLAGS:
7660 {
7661 int32_t indx = ri->d[rINDEX] / 10000;
7662 if ( ((unsigned)indx) > 3 )
7663 {
7664 Z_scripterrlog("Invalid index passed to SideWarpOverlayFlags[%d].\n. Valid indices are [0] through [3].\n", indx);
7665 ret = 0;
7666 }
7667 else if (mapscr *m = ResolveMapdata(ri->mapsref))
7668 {
7669 ret = (m->sidewarpoverlayflags & (1<<indx))?10000:0;
7670 }
7671 else
7672 {
7673 ret = 0;
7674 }
7675 break;
7676 }
7677
7678 case MAPDATATWARPRETSQR:
7679 {
7680 int32_t indx = ri->d[rINDEX] / 10000;
7681 if ( ((unsigned)indx) > 3)
7682 {
7683 ret = -10000;
7684 Z_scripterrlog("Invalid Array Index passed to mapdata->TileWarpReturnSquare[]: %d\n", indx);
7685
7686 }
7687 else if (mapscr *m = ResolveMapdata(ri->mapsref))
7688 {
7689 ret = ((m->warpreturnc>>(indx*2))&3) * 10000;
7690 }
7691 else
7692 {
7693 ret = -10000;
7694 }
7695 break;
7696 }
7697
7698 case MAPDATASWARPRETSQR:
7699 {
7700 int32_t indx = ri->d[rINDEX] / 10000;
7701 if ( ((unsigned)indx) > 3)
7702 {
7703 ret = -10000;
7704 Z_scripterrlog("Invalid Array Index passed to mapdata->TileWarpReturnSquare[]: %d\n", indx);
7705
7706 }
7707 else if (mapscr *m = ResolveMapdata(ri->mapsref))
7708 {
7709 ret = ((m->warpreturnc>>(8+(indx*2)))&3) * 10000;
7710 }
7711 else
7712 {
7713 ret = -10000;
7714 }
7715 break;
7716 }
7717
7718 case MAPDATAFFWIDTH:
7719 {
7720
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (mapscr *m = ResolveMapdata(ri->mapsref))
7721 {
7722 8 int32_t indx = (ri->d[rINDEX] / 10000)-1;
7723
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if ( indx < 0 || indx > MAXFFCS-1 )
7724 {
7725 Z_scripterrlog("Invalid FFC Index passed to MapData->FFCTileWidth[]: %d\n", indx+1);
7726 ret = -10000;
7727 break;
7728 }
7729 8 ret=(m->ffTileWidth(indx))*10000;
7730 8 }
7731 else
7732 {
7733 ret = -10000;
7734 }
7735 8 break;
7736 }
7737
7738 case MAPDATAFFHEIGHT:
7739 {
7740
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (mapscr *m = ResolveMapdata(ri->mapsref))
7741 {
7742 8 int32_t indx = (ri->d[rINDEX] / 10000)-1;
7743
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if ( indx < 0 || indx > MAXFFCS-1 )
7744 {
7745 Z_scripterrlog("Invalid FFC Index passed to MapData->FFCTileHeight[]: %d\n", indx+1);
7746 ret = -10000;
7747 break;
7748 }
7749 8 ret=(m->ffTileHeight(indx))*10000;
7750 8 }
7751 else
7752 {
7753 ret = -10000;
7754 }
7755 8 break;
7756
7757 }
7758
7759 case MAPDATAFFEFFECTWIDTH:
7760 {
7761
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (mapscr *m = ResolveMapdata(ri->mapsref))
7762 {
7763 5 int32_t indx = (ri->d[rINDEX] / 10000)-1;
7764
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
5 if ( indx < 0 || indx > MAXFFCS-1 )
7765 {
7766 Z_scripterrlog("Invalid FFC Index passed to MapData->FFCEffectWidth[]: %d\n", indx+1);
7767 ret = -10000;
7768 break;
7769 }
7770 5 ret=(m->ffEffectWidth(indx))*10000;
7771 5 }
7772 else
7773 {
7774 ret = -10000;
7775 }
7776 5 break;
7777 }
7778
7779 case MAPDATAFFEFFECTHEIGHT:
7780 {
7781
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (mapscr *m = ResolveMapdata(ri->mapsref))
7782 {
7783 5 int32_t indx = (ri->d[rINDEX] / 10000)-1;
7784
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
5 if ( indx < 0 || indx > MAXFFCS-1 )
7785 {
7786 Z_scripterrlog("Invalid FFC Index passed to MapData->FFCEffectHeight[]: %d\n", indx+1);
7787 ret = -10000;
7788 break;
7789 }
7790 5 ret=(m->ffEffectHeight(indx))*10000;
7791 5 }
7792 else
7793 {
7794 ret = -10000;
7795 }
7796 5 break;
7797 }
7798
7799
7800 case MAPDATAFFLINK: GET_MAPDATA_FFC_INDEX32(link, MAXFFCS-1); break;
7801
1/2
✓ Branch 0 taken 1556485 times.
✗ Branch 1 not taken.
1556485 case MAPDATAFFSCRIPT: GET_MAPDATA_FFC_INDEX32(script, MAXFFCS-1); break;
7802
7803 case MAPDATAINTID: //Same form as SetScreenD()
7804 //SetFFCInitD(ffindex, d, value)
7805 {
7806 2004 int32_t index = (ri->d[rINDEX]/10000);
7807 2004 int32_t d_index = ri->d[rINDEX2]/10000;
7808
7809
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2004 times.
2004 if (BC::checkBounds(d_index, 0, 7) != SH::_NoError)
7810 break;
7811
7812
1/2
✓ Branch 0 taken 2004 times.
✗ Branch 1 not taken.
2004 if (auto handle = ResolveMapdataFFC(ri->mapsref, index))
7813 2004 ret = handle.ffc->initd[d_index];
7814 else
7815 {
7816 ret = -10000;
7817 }
7818 2004 break;
7819 }
7820
7821
7822
7823 //initd //INT32 , 32 OF THESE, EACH WITH 10 INDICES.
7824
7825 case MAPDATAFFINITIALISED:
7826 {
7827 int32_t indx = ri->d[rINDEX] / 10000;
7828 if (indx < 0 || indx > MAXFFCS-1)
7829 {
7830 Z_scripterrlog("Invalid Index passed to mapdata->%s[]: %d\n", "FFCRunning", indx);
7831 ret = -10000;
7832 }
7833 else
7834 {
7835 if (mapscr *m = ResolveMapdata(ri->mapsref))
7836 {
7837 ret = get_script_engine_data(ScriptType::FFC, indx).initialized ? 10000 : 0;
7838 }
7839 else
7840 {
7841 ret = -10000;
7842 }
7843 }
7844 }
7845 break;
7846
7847 case MAPDATASCRIPTENTRY:
7848 {
7849 Z_scripterrlog("Unimplemented: %s\n", "ScriptEntry");
7850 ret = -10000;
7851 }
7852 break;
7853 case MAPDATASCRIPTOCCUPANCY:
7854 {
7855 Z_scripterrlog("Unimplemented: %s\n", "ScriptOccupancy");
7856 ret = -10000;
7857 }
7858 break;
7859 case MAPDATASCRIPTEXIT:
7860 {
7861 Z_scripterrlog("Unimplemented: %s\n", "ExitScript");
7862 ret = -10000;
7863 }
7864 break;
7865
7866 case MAPDATAOCEANSFX: GET_MAPDATA_VAR_BYTE(oceansfx); break; //B
7867 case MAPDATABOSSSFX: GET_MAPDATA_VAR_BYTE(bosssfx); break; //B
7868 case MAPDATASECRETSFX: GET_MAPDATA_VAR_BYTE(secretsfx); break; //B
7869 case MAPDATAHOLDUPSFX: GET_MAPDATA_VAR_BYTE(holdupsfx); break; //B
7870 case MAPDATASCREENMIDI:
7871 {
7872 if (mapscr *m = ResolveMapdata(ri->mapsref))
7873 {
7874 ret = ((m->screen_midi+(MIDIOFFSET_MAPSCR-MIDIOFFSET_ZSCRIPT)) *10000);
7875 }
7876 else
7877 {
7878 ret = -10000;
7879 }
7880 break;
7881 }
7882 case MAPDATALENSLAYER: GET_MAPDATA_VAR_BYTE(lens_layer); break; //B, OLD QUESTS ONLY?
7883 case MAPDATAMAP:
7884 {
7885
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (mapscr *m = ResolveMapdata(ri->mapsref))
7886 {
7887 18 ret = getMap(ri->mapsref) * 10000;
7888 18 }
7889 else
7890 {
7891 ret = -10000;
7892 }
7893 18 break;
7894 }
7895 case MAPDATASCREEN:
7896 {
7897
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if (mapscr *m = ResolveMapdata(ri->mapsref))
7898 {
7899 42 ret = getScreen(ri->mapsref) * 10000;
7900 42 }
7901 else
7902 {
7903 ret = -10000;
7904 }
7905 42 break;
7906 }
7907
7908 case MAPDATAFLAGS:
7909 {
7910
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (mapscr *m = ResolveMapdata(ri->mapsref))
7911 {
7912
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if ( get_qr(qr_OLDMAPDATAFLAGS) ) // TODO wtf, this QR was never used?
7913 {
7914 ret = get_screenflags(m,vbound(ri->d[rINDEX] / 10000,0,9));
7915 }
7916 else
7917 {
7918 6 int32_t flagid = (ri->d[rINDEX])/10000;
7919 //bool valtrue = ( value ? 10000 : 0);
7920
1/12
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
6 switch(flagid)
7921 {
7922 case 0: ret = (m->flags * 10000); break;
7923 case 1: ret = (m->flags2 * 10000); break;
7924 case 2: ret = (m->flags3 * 10000); break;
7925 case 3: ret = (m->flags4 * 10000); break;
7926 case 4: ret = (m->flags5 * 10000); break;
7927 case 5: ret = (m->flags6 * 10000); break;
7928 6 case 6: ret = (m->flags7 * 10000); break;
7929 case 7: ret = (m->flags8 * 10000); break;
7930 case 8: ret = (m->flags9 * 10000); break;
7931 case 9: ret = (m->flags10 * 10000); break;
7932 case 10: ret = (m->flags11 * 10000); break;
7933 default:
7934 {
7935 Z_scripterrlog("Invalid index passed to mapdata->flags[]: %d\n", flagid);
7936 ret = -10000;
7937 break;
7938
7939 }
7940 }
7941 }
7942 6 }
7943 else
7944 {
7945 ret = -10000;
7946 }
7947
7948 6 break;
7949 }
7950
7951 case MAPDATAMISCD:
7952 {
7953 int32_t indx = (ri->d[rINDEX])/10000;
7954 int32_t mi = get_mi(ri->mapsref);
7955 if(unsigned(mi) >= MAX_MI)
7956 {
7957 ret = 0;
7958 break;
7959 }
7960 if( ((unsigned)indx) > 7 )
7961 {
7962 scripting_log_error_with_context("Tried to reference an out-of-bounds array index for a screen's D[] array ({}); valid indices are from 0 to 7.", indx);
7963 ret = -10000;
7964 }
7965 else if (mapscr *m = ResolveMapdata(ri->mapsref))
7966 {
7967 ret = (game->screen_d[mi][indx]) * 10000;
7968 }
7969 else
7970 {
7971 ret = -10000;
7972 }
7973 break;
7974 }
7975
7976 case MAPDATACOMBODD:
7977 {
7978 37440165 int pos = ri->d[rINDEX] / 10000;
7979
1/2
✓ Branch 0 taken 37440165 times.
✗ Branch 1 not taken.
37440165 if (auto rpos_handle = ResolveMapdataPos(ri->mapsref, pos))
7980 {
7981 37440165 ret = rpos_handle.data() * 10000;
7982 37440165 }
7983 else
7984 {
7985 ret = -10000;
7986 }
7987 37440165 break;
7988 }
7989
7990 case MAPDATACOMBOCD:
7991 {
7992 37290663 int pos = ri->d[rINDEX] / 10000;
7993
1/2
✓ Branch 0 taken 37290663 times.
✗ Branch 1 not taken.
37290663 if (auto rpos_handle = ResolveMapdataPos(ri->mapsref, pos))
7994 {
7995 37290663 ret = rpos_handle.cset() * 10000;
7996 37290663 }
7997 else
7998 {
7999 ret = -10000;
8000 }
8001 37290663 break;
8002 }
8003
8004 case MAPDATACOMBOFD:
8005 {
8006 6005247 int pos = ri->d[rINDEX] / 10000;
8007
1/2
✓ Branch 0 taken 6005247 times.
✗ Branch 1 not taken.
6005247 if (auto rpos_handle = ResolveMapdataPos(ri->mapsref, pos))
8008 {
8009 6005247 ret = rpos_handle.sflag() * 10000;
8010 6005247 }
8011 else
8012 {
8013 ret = -10000;
8014 }
8015 6005247 break;
8016 }
8017
8018 case MAPDATACOMBOTD:
8019 {
8020 5030699 int pos = ri->d[rINDEX] / 10000;
8021
1/2
✓ Branch 0 taken 5030699 times.
✗ Branch 1 not taken.
5030699 if (auto rpos_handle = ResolveMapdataPos(ri->mapsref, pos))
8022 {
8023 5030699 ret = rpos_handle.ctype() * 10000;
8024 5030699 }
8025 else
8026 {
8027 ret = -10000;
8028 }
8029 5030699 break;
8030 }
8031
8032 case MAPDATACOMBOID:
8033 {
8034 388122 int pos = ri->d[rINDEX] / 10000;
8035
1/2
✓ Branch 0 taken 388122 times.
✗ Branch 1 not taken.
388122 if (auto rpos_handle = ResolveMapdataPos(ri->mapsref, pos))
8036 {
8037 388122 ret = rpos_handle.cflag() * 10000;
8038 388122 }
8039 else
8040 {
8041 ret = -10000;
8042 }
8043 388122 break;
8044 }
8045
8046 case MAPDATACOMBOSD:
8047 {
8048 90005 int pos = ri->d[rINDEX] / 10000;
8049
1/2
✓ Branch 0 taken 90005 times.
✗ Branch 1 not taken.
90005 if (auto rpos_handle = ResolveMapdataPos(ri->mapsref, pos))
8050 {
8051 90005 ret = (rpos_handle.combo().walk & 0xF) * 10000;
8052 90005 }
8053 else
8054 {
8055 ret = -10000;
8056 }
8057 90005 break;
8058 }
8059
8060 case MAPDATACOMBOED:
8061 {
8062 int pos = ri->d[rINDEX] / 10000;
8063 if (auto rpos_handle = ResolveMapdataPos(ri->mapsref, pos))
8064 {
8065 ret = ((rpos_handle.combo().walk & 0xF0)>>4) * 10000;
8066 }
8067 else
8068 {
8069 ret = -10000;
8070 }
8071 break;
8072 }
8073
8074 case MAPDATASCREENSTATED:
8075 {
8076
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45056 times.
45056 if (mapscr *m = ResolveMapdata(ri->mapsref))
8077 {
8078 45056 int32_t mi = get_mi(ri->mapsref);
8079
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45056 times.
45056 if(mi<0) {ret = 0;break;}
8080 45056 ret=((game->maps[mi]>>((ri->d[rINDEX]/10000)))&1)?10000:0;
8081 45056 }
8082 else
8083 {
8084 ret = 0;
8085 }
8086 45056 break;
8087 }
8088 case MAPDATAEXSTATED:
8089 {
8090 if (mapscr *m = ResolveMapdata(ri->mapsref))
8091 {
8092 int32_t mi = get_mi(ri->mapsref);
8093 if(mi<0) {ret = 0;break;}
8094 ret=((game->xstates[mi]>>((ri->d[rINDEX]/10000)))&1)?10000:0;
8095 }
8096 else
8097 {
8098 ret = 0;
8099 }
8100 break;
8101 }
8102 case MAPDATALENSSHOWS:
8103 {
8104 ret = 0;
8105 int ind = ri->d[rINDEX]/10000;
8106 if(ind < 0 || ind > 6)
8107 Z_scripterrlog("Bad index mapdata->LensShows[%d]\n",ind);
8108 else if (mapscr *m = ResolveMapdata(ri->mapsref))
8109 ret = (m->lens_show & (1<<ind)) ? 10000 : 0;
8110 break;
8111 }
8112 case MAPDATALENSHIDES:
8113 {
8114 ret = 0;
8115 int ind = ri->d[rINDEX]/10000;
8116 if(ind < 0 || ind > 6)
8117 Z_scripterrlog("Bad index mapdata->LensHides[%d]\n",ind);
8118 else if (mapscr *m = ResolveMapdata(ri->mapsref))
8119 ret = (m->lens_hide & (1<<ind)) ? 10000 : 0;
8120 break;
8121 }
8122 case MAPDATASCRDATASIZE:
8123 {
8124 ret = -10000;
8125 if (mapscr *m = ResolveMapdata(ri->mapsref))
8126 {
8127 int index = get_ref_map_index(ri->mapsref);
8128 if (index < 0) break;
8129
8130 ret = 10000*game->scriptDataSize(index);
8131 }
8132 break;
8133 }
8134 case MAPDATASCRDATA:
8135 {
8136 ret = -10000;
8137 if (mapscr *m = ResolveMapdata(ri->mapsref))
8138 {
8139 int mapindex = get_ref_map_index(ri->mapsref);
8140 if (mapindex < 0) break;
8141
8142 size_t indx = ri->d[rINDEX]/10000;
8143 if(indx >= game->scriptDataSize(mapindex))
8144 Z_scripterrlog("Invalid index passed to mapdata->Data[]: %d\n", indx);
8145 else ret = game->screen_data[mapindex][indx];
8146 }
8147 break;
8148 }
8149 case MAPDATASCREENFLAGSD:
8150 {
8151 if (mapscr *m = ResolveMapdata(ri->mapsref))
8152 {
8153 ret = get_screenflags(m,vbound(ri->d[rINDEX] / 10000,0,9));
8154 }
8155 else
8156 {
8157 ret = -10000;
8158 }
8159 break;
8160 }
8161
8162 case MAPDATASCREENEFLAGSD:
8163 {
8164 if (mapscr *m = ResolveMapdata(ri->mapsref))
8165 {
8166 ret = get_screeneflags(m,vbound(ri->d[rINDEX] / 10000,0,2));
8167 }
8168 else
8169 {
8170 ret = -10000;
8171 }
8172 break;
8173 }
8174 case MAPDATAGUYCOUNT:
8175 {
8176 if (mapscr *m = ResolveMapdata(ri->mapsref))
8177 {
8178 int mi = get_mi(ri->mapsref);
8179 if(mi > -1)
8180 {
8181 ret = game->guys[mi] * 10000;
8182 break;
8183 }
8184 }
8185 ret = -10000;
8186 break;
8187 }
8188 case MAPDATAEXDOOR:
8189 {
8190 ret = 0;
8191 if (mapscr *m = ResolveMapdata(ri->mapsref))
8192 {
8193 int mi = get_mi(ri->mapsref);
8194 if(mi < 0) break;
8195 int dir = SH::read_stack(ri->sp+1) / 10000;
8196 int ind = SH::read_stack(ri->sp+0) / 10000;
8197 if(unsigned(dir) > 3)
8198 Z_scripterrlog("Invalid dir '%d' passed to 'mapdata->GetExDoor()'; must be 0-3\n", dir);
8199 else if(unsigned(ind) > 7)
8200 Z_scripterrlog("Invalid index '%d' passed to 'mapdata->GetExDoor()'; must be 0-7\n", ind);
8201 else
8202 {
8203 int bit = 1<<ind;
8204 ret = (game->xdoors[mi][dir]&bit) ? 10000 : 0;
8205 }
8206 }
8207 break;
8208 }
8209
8210 case MAPDATA_FLAG:
8211 {
8212 if (mapscr* scr = ResolveMapdata(ri->mapsref))
8213 {
8214 int32_t index = ri->d[rINDEX] / 10000;
8215 if (BC::checkIndex(index, 0, 8*11 - 1) != SH::_NoError)
8216 {
8217 ret = 0;
8218 break;
8219 }
8220
8221 ret = (&scr->flags)[index/8] & (1 << (index%8)) ? 10000 : 0;
8222 break;
8223 }
8224
8225 ret = 0;
8226 break;
8227 }
8228
8229 ///----------------------------------------------------------------------------------------------------//
8230 //shopdata sd-> variables
8231
8232 case SHOPDATATYPE:
8233 {
8234 int32_t ref = ri->shopsref;
8235 if ( ref > NUMINFOSHOPS || ref < 0 ) ret = 0;
8236 else ret = ( ( ref <= NUMSHOPS ) ? 10000 : 20000 );
8237 break;
8238 }
8239 case SHOPDATAITEM:
8240 {
8241
8242 int32_t ref = ri->shopsref;
8243 bool isInfo = ( ref >= NUMSHOPS && ref <= NUMINFOSHOPS );
8244 int32_t indx = ri->d[rINDEX] / 10000;
8245 if ( indx < 0 || indx > 2 )
8246 {
8247 Z_scripterrlog("Invalid Array Index passed to shopdata->%s: %d\n", indx, "Item");
8248 ret = -10000;
8249 }
8250 else
8251 {
8252 if ( isInfo )
8253 {
8254 Z_scripterrlog("Attempted to load an 'item' from an infoshop, using shop ID: %d\n", ri->shopsref);
8255 ret = -10000;
8256 }
8257 else
8258 {
8259 ret = ((int32_t)(QMisc.shop[ref].item[indx]) * 10000);
8260 }
8261 }
8262 break;
8263 }
8264
8265
8266 // GET_SHOPDATA_VAR_INDEX(item, "Item", 2); break;
8267 case SHOPDATAHASITEM:
8268 {
8269
8270 int32_t ref = ri->shopsref;
8271 bool isInfo = ( ref >= NUMSHOPS && ref <= NUMINFOSHOPS );
8272 int32_t indx = ri->d[rINDEX] / 10000;
8273 if ( indx < 0 || indx > 2 )
8274 {
8275 Z_scripterrlog("Invalid Array Index passed to shopdata->%s: %d\n", indx, "HasItem");
8276 ret = -10000;
8277 }
8278 else
8279 {
8280 if ( isInfo )
8281 {
8282 Z_scripterrlog("Attempted to load 'hasitem' from an infoshop, using shop ID: %d\n", ri->shopsref);
8283 ret = -10000;
8284 }
8285 else
8286 {
8287 ret = ((int32_t)(QMisc.shop[ref].hasitem[indx]) * 10000);
8288 }
8289 }
8290 break;
8291 }
8292
8293
8294 //GET_SHOPDATA_VAR_INDEX(hasitem, "HasItem", 2); break;
8295 case SHOPDATAPRICE:
8296 {
8297
8298 int32_t ref = ri->shopsref;
8299 bool isInfo = ( ref >= NUMSHOPS && ref <= NUMINFOSHOPS );
8300 int32_t indx = ri->d[rINDEX] / 10000;
8301 if ( indx < 0 || indx > 2 )
8302 {
8303 Z_scripterrlog("Invalid Array Index passed to shopdata->%s: %d\n", indx, "Price");
8304 ret = -10000;
8305 }
8306 else
8307 {
8308 if ( isInfo )
8309 {
8310 ret = ((int32_t)(QMisc.info[ref - NUMSHOPS].price[indx]) * 10000);
8311 }
8312 else
8313 {
8314 ret = ((int32_t)(QMisc.shop[ref].price[indx]) * 10000);
8315 }
8316 }
8317 break;
8318 }
8319
8320
8321 //GET_SHOPDATA_VAR_INDEX(price, "Price", 2); break;
8322 //Pay for info
8323 case SHOPDATASTRING:
8324 {
8325 int32_t ref = ri->shopsref;
8326 if (ref < NUMSHOPS || ref > NUMINFOSHOPS)
8327 {
8328 Z_scripterrlog("Invalid shop pointer passed to shopdata->String[]: %d\n", ref);
8329 ret = -10000;
8330 }
8331 else
8332 {
8333 bool isInfo = ( ref >= NUMSHOPS && ref <= NUMINFOSHOPS );
8334 int32_t indx = ri->d[rINDEX] / 10000;
8335 if ( indx < 0 || indx > 2 )
8336 {
8337 Z_scripterrlog("Invalid Array Index passed to shopdata->%s: %d\n", indx, "String");
8338 }
8339 else
8340 {
8341 if ( isInfo )
8342 {
8343 ret = ((int32_t)(QMisc.info[ref - NUMSHOPS].str[indx]) * 10000);
8344 }
8345 else
8346 {
8347 ret = ((int32_t)(QMisc.shop[ref].str[indx]) * 10000);
8348 }
8349 }
8350
8351
8352 }
8353
8354 //GET_SHOPDATA_VAR_INDEX(str, String, 2); break;
8355 break;
8356 }
8357
8358
8359 ///----------------------------------------------------------------------------------------------------//
8360 //dmapdata dmd-> variables
8361
8362 //getter
8363 701 case DMAPDATAID: ret = ri->dmapsref*10000; break; //read-only, equal to CurrentDMap
8364
8365 case DMAPDATAMAP: //byte
8366 {
8367 225 ret = ((byte)DMaps[ri->dmapsref].map + 1) * 10000; break;
8368 }
8369 case DMAPDATALEVEL: //word
8370 {
8371 ret = ((word)DMaps[ri->dmapsref].level) * 10000; break;
8372 }
8373 case DMAPDATAOFFSET: //char
8374 {
8375 6 ret = ((char)DMaps[ri->dmapsref].xoff) * 10000; break;
8376 }
8377 case DMAPDATACOMPASS: //byte
8378 {
8379 ret = ((byte)DMaps[ri->dmapsref].compass) * 10000; break;
8380 }
8381 case DMAPDATAPALETTE: //word
8382 {
8383 212 ret = ((word)DMaps[ri->dmapsref].color) * 10000; break;
8384 }
8385 case DMAPSCRIPT: //word
8386 {
8387 19 ret = (DMaps[ri->dmapsref].script) * 10000; break;
8388 }
8389 case DMAPDATAMIDI: //byte
8390 {
8391 ret = (DMaps[ri->dmapsref].midi-MIDIOFFSET_DMAP) * 10000; break;
8392 }
8393 case DMAPDATACONTINUE: //byte
8394 {
8395 ret = ((byte)DMaps[ri->dmapsref].cont) * 10000; break;
8396 }
8397 case DMAPDATATYPE: //byte
8398 {
8399 1124 ret = ((byte)DMaps[ri->dmapsref].type&dmfTYPE) * 10000; break;
8400 }
8401 case DMAPDATASIDEVIEW: //byte
8402 {
8403 1095768 ret = ((DMaps[ri->dmapsref].sideview) ? 10000 : 0); break;
8404 }
8405 case DMAPDATAGRID: //byte[8] --array
8406 {
8407 43092 int32_t indx = ri->d[rINDEX] / 10000;
8408
2/4
✓ Branch 0 taken 43092 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 43092 times.
43092 if ( indx < 0 || indx > 7 )
8409 {
8410 scripting_log_error_with_context("Invalid index: {}", indx);
8411 ret = -10000;
8412 break;
8413 }
8414 else
8415 {
8416 43092 ret = ((byte)DMaps[ri->dmapsref].grid[indx]) * 10000; break;
8417 }
8418 }
8419 case DMAPINITD: //byte[8] --array
8420 {
8421 45 int32_t indx = ri->d[rINDEX] / 10000;
8422
2/4
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 45 times.
45 if ( indx < 0 || indx > 7 )
8423 {
8424 scripting_log_error_with_context("Invalid index: {}", indx);
8425 ret = -10000;
8426 break;
8427 }
8428 else
8429 {
8430 45 ret = DMaps[ri->dmapsref].initD[indx]; break;
8431 }
8432 }
8433 case DMAPDATAMINIMAPTILE: //word - two of these, so let's do MinimapTile[2]
8434 {
8435 1402 int32_t indx = ri->d[rINDEX] / 10000;
8436
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 718 times.
✓ Branch 2 taken 684 times.
1402 switch(indx)
8437 {
8438 718 case 0: { ret = ((word)DMaps[ri->dmapsref].minimap_1_tile) * 10000; break; }
8439 684 case 1: { ret = ((word)DMaps[ri->dmapsref].minimap_2_tile) * 10000; break; }
8440 default:
8441 {
8442 scripting_log_error_with_context("Invalid index: {}", indx);
8443 ret = -10000;
8444 break;
8445 }
8446 }
8447 1402 break;
8448 }
8449 case DMAPDATAMINIMAPCSET: //byte - two of these, so let's do MinimapCSet[2]
8450 {
8451 17 int32_t indx = ri->d[rINDEX] / 10000;
8452
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
17 switch(indx)
8453 {
8454 17 case 0: { ret = ((byte)DMaps[ri->dmapsref].minimap_1_cset) * 10000; break; }
8455 case 1: { ret = ((byte)DMaps[ri->dmapsref].minimap_2_cset) * 10000; break; }
8456 default:
8457 {
8458 scripting_log_error_with_context("Invalid index: {}", indx);
8459 ret = -10000;
8460 break;
8461 }
8462 }
8463 17 break;
8464 }
8465 case DMAPDATALARGEMAPTILE: //word -- two of these, so let's to LargemapTile[2]
8466 {
8467 int32_t indx = ri->d[rINDEX] / 10000;
8468 switch(indx)
8469 {
8470 case 0: { ret = ((word)DMaps[ri->dmapsref].largemap_1_tile) * 10000; break; }
8471 case 1: { ret = ((word)DMaps[ri->dmapsref].largemap_2_tile) * 10000; break; }
8472 default:
8473 {
8474 scripting_log_error_with_context("Invalid index: {}", indx);
8475 ret = -10000;
8476 break;
8477 }
8478 }
8479 break;
8480 }
8481 case DMAPDATALARGEMAPCSET: //word -- two of these, so let's to LargemaCSet[2]
8482 {
8483 int32_t indx = ri->d[rINDEX] / 10000;
8484 switch(indx)
8485 {
8486 case 0: { ret = ((byte)DMaps[ri->dmapsref].largemap_1_cset) * 10000; break; }
8487 case 1: { ret = ((byte)DMaps[ri->dmapsref].largemap_2_cset) * 10000; break; }
8488 default:
8489 {
8490 scripting_log_error_with_context("Invalid index: {}", indx);
8491 ret = -10000;
8492 break;
8493 }
8494 }
8495 break;
8496 }
8497 case DMAPDATAMUISCTRACK: //byte
8498 {
8499 ret = ((byte)DMaps[ri->dmapsref].tmusictrack) * 10000; break;
8500 }
8501 case DMAPDATASUBSCRA:
8502 {
8503 ret = ((byte)DMaps[ri->dmapsref].active_subscreen) * 10000; break;
8504 }
8505 case DMAPDATASUBSCRP:
8506 {
8507 5120 ret = ((byte)DMaps[ri->dmapsref].passive_subscreen) * 10000; break;
8508 }
8509 case DMAPDATASUBSCRO:
8510 {
8511 ret = ((byte)DMaps[ri->dmapsref].overlay_subscreen) * 10000; break;
8512 }
8513 case DMAPDATADISABLEDITEMS: //byte[MAXITEMS]
8514 {
8515 int32_t indx = ri->d[rINDEX] / 10000;
8516 if ( indx < 0 || indx > (MAXITEMS-1) )
8517 {
8518 scripting_log_error_with_context("Invalid index: {}", indx);
8519 ret = -10000;
8520 break;
8521 }
8522 else
8523 {
8524 ret = ((byte)DMaps[ri->dmapsref].disableditems[indx]) * 10000; break;
8525 }
8526 }
8527 case DMAPDATAFLAGARR: //int32_t
8528 {
8529 6 int32_t indx = ri->d[rINDEX] / 10000;
8530
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if ( ((unsigned)indx) > 31 )
8531 {
8532 scripting_log_error_with_context("Invalid index: {}", indx);
8533 ret = -10000;
8534 break;
8535 }
8536 6 ret = ((DMaps[ri->dmapsref].flags&(1<<indx)) ? 10000:0);
8537 6 break;
8538 }
8539 case DMAPDATAFLAGS: //int32_t
8540 {
8541 ret = (DMaps[ri->dmapsref].flags) * 10000; break;
8542 }
8543 case DMAPDATAMIRRDMAP:
8544 {
8545 ret = (DMaps[ri->dmapsref].mirrorDMap) * 10000; break;
8546 }
8547 case DMAPDATALOOPSTART:
8548 {
8549 ret = (DMaps[ri->dmapsref].tmusic_loop_start); break;
8550 }
8551 case DMAPDATALOOPEND:
8552 {
8553 ret = (DMaps[ri->dmapsref].tmusic_loop_end); break;
8554 }
8555 case DMAPDATAXFADEIN:
8556 {
8557 ret = (DMaps[ri->dmapsref].tmusic_xfade_in * 10000); break;
8558 }
8559 case DMAPDATAXFADEOUT:
8560 {
8561 ret = (DMaps[ri->dmapsref].tmusic_xfade_out * 10000); break;
8562 }
8563 case DMAPDATAINTROSTRINGID:
8564 {
8565 ret = (DMaps[ri->dmapsref].intro_string_id * 10000); break;
8566 }
8567 case MUSICUPDATECOND:
8568 {
8569 ret = ((byte)FFCore.music_update_cond) * 10000; break;
8570 }
8571 case MUSICUPDATEFLAGS:
8572 {
8573 int32_t indx = ri->d[rINDEX] / 10000;
8574 if (indx < 0 || indx > 2)
8575 {
8576 scripting_log_error_with_context("Invalid index: {}", indx);
8577 }
8578 ret = ((FFCore.music_update_flags >> indx) & 1) ? 10000 : 0; break;
8579 }
8580 case DMAPDATAASUBSCRIPT: //word
8581 {
8582 22016 ret = (DMaps[ri->dmapsref].active_sub_script) * 10000; break;
8583 }
8584 case DMAPDATAMAPSCRIPT: //byte
8585 {
8586 ret = (DMaps[ri->dmapsref].onmap_script) * 10000; break;
8587 }
8588 case DMAPDATAPSUBSCRIPT: //word
8589 {
8590 ret = (DMaps[ri->dmapsref].passive_sub_script) * 10000; break;
8591 }
8592 case DMAPDATASUBINITD: //byte[8] --array
8593 {
8594 int32_t indx = ri->d[rINDEX] / 10000;
8595 if ( indx < 0 || indx > 7 )
8596 {
8597 scripting_log_error_with_context("Invalid index: {}", indx);
8598 ret = -10000;
8599 break;
8600 }
8601 else
8602 {
8603 ret = DMaps[ri->dmapsref].sub_initD[indx]; break;
8604 }
8605 }
8606
8607 case DMAPDATAMAPINITD: //byte[8] --array
8608 {
8609 int32_t indx = ri->d[rINDEX] / 10000;
8610 if ( indx < 0 || indx > 7 )
8611 {
8612 scripting_log_error_with_context("Invalid index: {}", indx);
8613 ret = -10000;
8614 break;
8615 }
8616 else
8617 {
8618 ret = DMaps[ri->dmapsref].onmap_initD[indx]; break;
8619 }
8620 }
8621
8622 case DMAPDATACHARTED:
8623 {
8624 int32_t screen = ri->d[rINDEX] / 10000;
8625 ret = -10000;
8626 if(ri->dmapsref >= MAXDMAPS)
8627 {
8628 scripting_log_error_with_context("Invalid dmap reference: {}", ri->dmapsref);
8629 }
8630 // else if((DMaps[get_currdmap()].type&dmfTYPE) == dmOVERW)
8631 // {
8632 // Z_scripterrlog("dmapdata->Charted[] cannot presently be used on Overworld-type dmaps\n");
8633 // }
8634 else if(((unsigned)(screen)) > 127)
8635 {
8636 scripting_log_error_with_context("Invalid screen: {}", screen);
8637 }
8638 else
8639 {
8640 int32_t col = (screen&15)-(DMaps[ri->dmapsref].type==dmOVERW ? 0 : DMaps[ri->dmapsref].xoff);
8641 if((DMaps[ri->dmapsref].type&dmfTYPE)!=dmOVERW ? (((unsigned)col) > 7) : (((unsigned)col) > 15))
8642 break; //Out-of-bounds; don't attempt read!
8643 int32_t di = (ri->dmapsref << 7) + (screen & 0x7F);
8644 ret = 10000 * game->bmaps[di];
8645 }
8646 break;
8647 }
8648 //case DMAPDATAGRAVITY: //unimplemented
8649 //case DMAPDATAJUMPLAYER: //unimplemented
8650
8651 ///----------------------------------------------------------------------------------------------------//
8652 //messagedata msgd-> variables
8653 case MESSAGEDATANEXT: //W
8654 {
8655 int32_t ID = ri->zmsgref;
8656
8657 if(BC::checkMessage(ID) != SH::_NoError)
8658 {
8659 ret = -10000; break;
8660 }
8661 else
8662 {
8663 ret = ((int32_t)MsgStrings[ID].nextstring) * 10000;
8664 break;
8665 }
8666 }
8667
8668 case MESSAGEDATATILE: //W
8669 {
8670 int32_t ID = ri->zmsgref;
8671
8672 if(BC::checkMessage(ID) != SH::_NoError)
8673 ret = -10000;
8674 else
8675 ret = ((int32_t)MsgStrings[ID].tile) * 10000;
8676 break;
8677 }
8678
8679 case MESSAGEDATACSET: //b
8680 {
8681 int32_t ID = ri->zmsgref;
8682
8683 if(BC::checkMessage(ID) != SH::_NoError)
8684 ret = -10000;
8685 else
8686 ret = ((int32_t)MsgStrings[ID].cset) * 10000;
8687 break;
8688 }
8689 case MESSAGEDATATRANS: //BOOL
8690 {
8691 int32_t ID = ri->zmsgref;
8692
8693 if(BC::checkMessage(ID) != SH::_NoError)
8694 ret = -10000;
8695 else
8696 ret = ((MsgStrings[ID].trans)?10000:0);
8697 break;
8698 }
8699 case MESSAGEDATAFONT: //B
8700 {
8701 int32_t ID = ri->zmsgref;
8702
8703 if(BC::checkMessage(ID) != SH::_NoError)
8704 ret = -10000;
8705 else
8706 ret = (int32_t)MsgStrings[ID].font * 10000;
8707 break;
8708 }
8709 case MESSAGEDATAX: //SHORT
8710 {
8711 int32_t ID = ri->zmsgref;
8712
8713 if(BC::checkMessage(ID) != SH::_NoError)
8714 ret = -10000;
8715 else
8716 ret = ((int32_t)MsgStrings[ID].x) * 10000;
8717 break;
8718 }
8719 case MESSAGEDATAY: //SHORT
8720 {
8721 int32_t ID = ri->zmsgref;
8722
8723 if(BC::checkMessage(ID) != SH::_NoError)
8724 ret = -10000;
8725 else
8726 ret = ((int32_t)MsgStrings[ID].y) * 10000;
8727 break;
8728 }
8729 case MESSAGEDATAW: //UNSIGNED SHORT
8730 {
8731 int32_t ID = ri->zmsgref;
8732
8733 if(BC::checkMessage(ID) != SH::_NoError)
8734 ret = -10000;
8735 else
8736 ret = ((int32_t)MsgStrings[ID].w) * 10000;
8737 break;
8738 }
8739 case MESSAGEDATAH: //UNSIGNED SHORT
8740 {
8741 int32_t ID = ri->zmsgref;
8742
8743 if(BC::checkMessage(ID) != SH::_NoError)
8744 ret = -10000;
8745 else
8746 ret = ((int32_t)MsgStrings[ID].h) * 10000;
8747 break;
8748 }
8749 case MESSAGEDATASFX: //BYTE
8750 {
8751 int32_t ID = ri->zmsgref;
8752
8753 if(BC::checkMessage(ID) != SH::_NoError)
8754 ret = -10000;
8755 else
8756 ret = ((int32_t)MsgStrings[ID].sfx) * 10000;
8757 break;
8758 }
8759 case MESSAGEDATALISTPOS: //WORD
8760 {
8761 int32_t ID = ri->zmsgref;
8762
8763 if(BC::checkMessage(ID) != SH::_NoError)
8764 ret = -10000;
8765 else
8766 ret = ((int32_t)MsgStrings[ID].listpos) * 10000;
8767 break;
8768 }
8769 case MESSAGEDATAVSPACE: //BYTE
8770 {
8771 int32_t ID = ri->zmsgref;
8772
8773 if(BC::checkMessage(ID) != SH::_NoError)
8774 ret = -10000;
8775 else
8776 ret = ((int32_t)MsgStrings[ID].vspace) * 10000;
8777 break;
8778 }
8779 case MESSAGEDATAHSPACE: //BYTE
8780 {
8781 int32_t ID = ri->zmsgref;
8782
8783 if(BC::checkMessage(ID) != SH::_NoError)
8784 ret = -10000;
8785 else
8786 ret = ((int32_t)MsgStrings[ID].hspace) * 10000;
8787 break;
8788 }
8789 case MESSAGEDATAFLAGS: //BYTE
8790 {
8791 int32_t ID = ri->zmsgref;
8792
8793 if(BC::checkMessage(ID) != SH::_NoError)
8794 ret = -10000;
8795 else
8796 ret = ((int32_t)MsgStrings[ID].stringflags) * 10000;
8797 break;
8798 }
8799 case MESSAGEDATAMARGINS: //BYTE, 4
8800 {
8801 int32_t indx = ri->d[rINDEX] / 10000;
8802 if ( indx < 0 || indx > 3 )
8803 {
8804 scripting_log_error_with_context("Invalid index: {}", indx);
8805 ret = -10000;
8806 break;
8807 }
8808 int32_t ID = ri->zmsgref;
8809
8810 if(BC::checkMessage(ID) != SH::_NoError)
8811 ret = -10000;
8812 else
8813 ret = ((int32_t)MsgStrings[ID].margins[indx]) * 10000;
8814 break;
8815 }
8816 case MESSAGEDATAPORTTILE: //INT
8817 {
8818 int32_t ID = ri->zmsgref;
8819
8820 if(BC::checkMessage(ID) != SH::_NoError)
8821 ret = -10000;
8822 else
8823 ret = ((int32_t)MsgStrings[ID].portrait_tile) * 10000;
8824 break;
8825 }
8826 case MESSAGEDATAPORTCSET: //BYTE
8827 {
8828 int32_t ID = ri->zmsgref;
8829
8830 if(BC::checkMessage(ID) != SH::_NoError)
8831 ret = -10000;
8832 else
8833 ret = ((int32_t)MsgStrings[ID].portrait_cset) * 10000;
8834 break;
8835 }
8836 case MESSAGEDATAPORTX: //BYTE
8837 {
8838 int32_t ID = ri->zmsgref;
8839
8840 if(BC::checkMessage(ID) != SH::_NoError)
8841 ret = -10000;
8842 else
8843 ret = ((int32_t)MsgStrings[ID].portrait_x) * 10000;
8844 break;
8845 }
8846 case MESSAGEDATAPORTY: //BYTE
8847 {
8848 int32_t ID = ri->zmsgref;
8849
8850 if(BC::checkMessage(ID) != SH::_NoError)
8851 ret = -10000;
8852 else
8853 ret = ((int32_t)MsgStrings[ID].portrait_y) * 10000;
8854 break;
8855 }
8856 case MESSAGEDATAPORTWID: //BYTE
8857 {
8858 int32_t ID = ri->zmsgref;
8859
8860 if(BC::checkMessage(ID) != SH::_NoError)
8861 ret = -10000;
8862 else
8863 ret = ((int32_t)MsgStrings[ID].portrait_tw) * 10000;
8864 break;
8865 }
8866 case MESSAGEDATAPORTHEI: //BYTE
8867 {
8868 int32_t ID = ri->zmsgref;
8869
8870 if(BC::checkMessage(ID) != SH::_NoError)
8871 ret = -10000;
8872 else
8873 ret = ((int32_t)MsgStrings[ID].portrait_th) * 10000;
8874 break;
8875 }
8876 case MESSAGEDATATEXTLEN: //BYTE
8877 {
8878 int32_t ID = ri->zmsgref;
8879
8880 if(BC::checkMessage(ID) != SH::_NoError)
8881 ret = -10000;
8882 else
8883 ret = int32_t(MsgStrings[ID].s.size()) * 10000;
8884 break;
8885 }
8886 case MESSAGEDATATEXTWID:
8887 {
8888 ret = do_msgwidth(ri->zmsgref)*10000;
8889 break;
8890 }
8891 case MESSAGEDATATEXTHEI:
8892 {
8893 ret = do_msgheight(ri->zmsgref)*10000;
8894 break;
8895 }
8896 case MESSAGEDATAFLAGSARR: //BOOL, 7
8897 {
8898 int32_t indx = ri->d[rINDEX] / 10000;
8899 int32_t ID = ri->zmsgref;
8900
8901 if(BC::checkMessage(ID) != SH::_NoError)
8902 ret = -10000;
8903 else
8904 {
8905 switch(indx)
8906 {
8907 case 0:
8908 ret = (MsgStrings[ID].stringflags & STRINGFLAG_WRAP)!=0 ? 10000 : 0;
8909 break;
8910 case 1:
8911 ret = (MsgStrings[ID].stringflags & STRINGFLAG_CONT)!=0 ? 10000 : 0;
8912 break;
8913 case 2: //Not implemented
8914 ret = 0;//ret = (MsgStrings[ID].stringflags & STRINGFLAG_CENTER)!=0 ? 10000 : 0;
8915 break;
8916 case 3: //Not implemented
8917 ret = 0;//ret = (MsgStrings[ID].stringflags & STRINGFLAG_RIGHT)!=0 ? 10000 : 0;
8918 break;
8919 case 4:
8920 ret = (MsgStrings[ID].stringflags & STRINGFLAG_FULLTILE)!=0 ? 10000 : 0;
8921 break;
8922 case 5:
8923 ret = (MsgStrings[ID].stringflags & STRINGFLAG_TRANS_BG)!=0 ? 10000 : 0;
8924 break;
8925 case 6:
8926 ret = (MsgStrings[ID].stringflags & STRINGFLAG_TRANS_FG)!=0 ? 10000 : 0;
8927 break;
8928 default:
8929 Z_scripterrlog("Invalid index supplied to messagedata->Flags[]: %d\n", indx);
8930 ret = -10000;
8931 }
8932 }
8933 break;
8934 }
8935
8936 ///----------------------------------------------------------------------------------------------------//
8937 //combodata cd-> Getter variables
8938 #define GET_COMBO_VAR_INT(member) \
8939 { \
8940 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
8941 { \
8942 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
8943 ret = -10000; \
8944 } \
8945 else \
8946 { \
8947 ret = (combobuf[ri->combosref].member *10000); \
8948 } \
8949 } \
8950
8951 #define GET_COMBO_VAR_BYTE(member) \
8952 { \
8953 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
8954 { \
8955 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
8956 ret = -10000; \
8957 } \
8958 else \
8959 { \
8960 ret = (combobuf[ri->combosref].member *10000); \
8961 } \
8962 } \
8963
8964 #define GET_COMBO_VAR_DWORD(member) \
8965 { \
8966 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
8967 { \
8968 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
8969 ret = -10000; \
8970 } \
8971 else \
8972 { \
8973 ret = (combobuf[ri->combosref].member *10000); \
8974 } \
8975 } \
8976
8977 #define GET_COMBO_VAR_INDEX(member, indexbound) \
8978 { \
8979 int32_t indx = ri->d[rINDEX] / 10000; \
8980 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
8981 { \
8982 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
8983 ret = -10000; \
8984 } \
8985 else if ( indx < 0 || indx >= indexbound ) \
8986 { \
8987 scripting_log_error_with_context("Invalid Array Index: {}", indx); \
8988 ret = -10000; \
8989 } \
8990 else \
8991 { \
8992 ret = (combobuf[ri->combosref].member[indx] * 10000); \
8993 } \
8994 }
8995
8996 #define GET_COMBO_BYTE_INDEX(member, indexbound) \
8997 { \
8998 int32_t indx = ri->d[rINDEX] / 10000; \
8999 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
9000 { \
9001 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
9002 ret = -10000; \
9003 } \
9004 else if ( indx < 0 || indx >= indexbound ) \
9005 { \
9006 scripting_log_error_with_context("Invalid Array Index: {}", indx); \
9007 ret = -10000; \
9008 } \
9009 else \
9010 { \
9011 ret = (combobuf[ri->combosref].member[indx] * 100000); \
9012 } \
9013 }
9014
9015 #define GET_COMBO_FLAG(member, indexbound) \
9016 { \
9017 int32_t flag = (value/10000); \
9018 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
9019 { \
9020 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
9021 } \
9022 else \
9023 { \
9024 ret = (combobuf[ri->combosref].member&flag) ? 10000 : 0); \
9025 } \
9026 } \
9027
9028 //comboclass macros
9029
9030 #define GET_COMBOCLASS_VAR_INT(member) \
9031 { \
9032 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
9033 { \
9034 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
9035 ret = -10000; \
9036 } \
9037 else \
9038 { \
9039 ret = (combo_class_buf[combobuf[ri->combosref].type].member *10000); \
9040 } \
9041 } \
9042
9043 #define GET_COMBOCLASS_VAR_BYTE(member) \
9044 { \
9045 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
9046 { \
9047 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
9048 ret = -10000; \
9049 } \
9050 else \
9051 { \
9052 ret = (combo_class_buf[combobuf[ri->combosref].type].member *10000); \
9053 } \
9054 } \
9055
9056 #define GET_COMBOCLASS_VAR_DWORD(member) \
9057 { \
9058 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
9059 { \
9060 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
9061 ret = -10000; \
9062 } \
9063 else \
9064 { \
9065 ret = (combo_class_buf[combobuf[ri->combosref].type].member *10000); \
9066 } \
9067 } \
9068
9069 #define GET_COMBOCLASS_VAR_INDEX(member, indexbound) \
9070 { \
9071 int32_t indx = ri->d[rINDEX] / 10000; \
9072 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
9073 { \
9074 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
9075 ret = -10000; \
9076 } \
9077 else if ( indx < 0 || indx > indexbound ) \
9078 { \
9079 scripting_log_error_with_context("Invalid Array Index: {}", indx); \
9080 ret = -10000; \
9081 } \
9082 else \
9083 { \
9084 ret = (combo_class_buf[combobuf[ri->combosref].type].member[indx] * 10000); \
9085 } \
9086 }
9087
9088 #define GET_COMBOCLASS_BYTE_INDEX(member, indexbound) \
9089 { \
9090 int32_t indx = ri->d[rINDEX] / 10000; \
9091 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
9092 { \
9093 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
9094 ret = -10000; \
9095 } \
9096 else if ( indx < 0 || indx > indexbound ) \
9097 { \
9098 scripting_log_error_with_context("Invalid Array Index: {}", indx); \
9099 ret = -10000; \
9100 } \
9101 else \
9102 { \
9103 ret = (combo_class_buf[combobuf[ri->combosref].type].member[indx] * 100000); \
9104 } \
9105 }
9106
9107 #define GET_COMBOCLASS_FLAG(member, indexbound) \
9108 { \
9109 int32_t flag = (value/10000); \
9110 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
9111 { \
9112 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
9113 } \
9114 else \
9115 { \
9116 ret = (combo_class_buf[combobuf[ri->combosref].type].member&flag) ? 10000 : 0); \
9117 } \
9118 } \
9119
9120 case COMBOXR:
9121 {
9122 //ri->combosref = id; //'this' pointer
9123 //ri->comboposref = i; //used for X(), Y(), Layer(), and so forth.
9124
1/2
✓ Branch 0 taken 60340 times.
✗ Branch 1 not taken.
60340 if ( curScriptType == ScriptType::Combo )
9125 {
9126 60340 rpos_t rpos = combopos_ref_to_rpos(ri->comboposref);
9127 60340 ret = (( COMBOX_REGION((rpos)) ) * 10000); //comboscriptstack[i]
9128 //this may be wrong...may need a special new var for this, storing the exact combopos
9129 //i is the current script number
9130 60340 }
9131 else
9132 {
9133 scripting_log_error_with_context("Can only be called by combodata scripts, but you tried to use it from script type {}, script token {}", ScriptTypeToString(curScriptType), comboscriptmap[ri->combosref].scriptname);
9134 ret = -10000;
9135 }
9136 60340 break;
9137 }
9138
9139 case COMBOYR:
9140 {
9141
1/2
✓ Branch 0 taken 12211 times.
✗ Branch 1 not taken.
12211 if ( curScriptType == ScriptType::Combo )
9142 {
9143 12211 rpos_t rpos = combopos_ref_to_rpos(ri->comboposref);
9144 12211 ret = (( COMBOY_REGION((rpos)) ) * 10000); //comboscriptstack[i]
9145 12211 }
9146 else
9147 {
9148 scripting_log_error_with_context("Can only be called by combodata scripts, but you tried to use it from script type {}, script token {}", ScriptTypeToString(curScriptType), comboscriptmap[ri->combosref].scriptname); ret = -10000;
9149 }
9150 12211 break;
9151 }
9152 case COMBOPOSR:
9153 {
9154
1/2
✓ Branch 0 taken 208371 times.
✗ Branch 1 not taken.
208371 if ( curScriptType == ScriptType::Combo )
9155 {
9156 208371 rpos_t rpos = combopos_ref_to_rpos(ri->comboposref);
9157 208371 ret = (int)rpos * 10000; //comboscriptstack[i]
9158 208371 }
9159 else
9160 {
9161 scripting_log_error_with_context("Can only be called by combodata scripts, but you tried to use it from script type {}, script token {}", ScriptTypeToString(curScriptType), comboscriptmap[ri->combosref].scriptname); ret = -10000;
9162 }
9163 208371 break;
9164 }
9165 case COMBOLAYERR:
9166 {
9167
1/2
✓ Branch 0 taken 19038 times.
✗ Branch 1 not taken.
19038 if ( curScriptType == ScriptType::Combo )
9168 {
9169 19038 int32_t layer = combopos_ref_to_layer(ri->comboposref);
9170 19038 ret = layer * 10000; //comboscriptstack[i]
9171 19038 }
9172 else
9173 {
9174 scripting_log_error_with_context("Can only be called by combodata scripts, but you tried to use it from script type {}, script token {}", ScriptTypeToString(curScriptType), comboscriptmap[ri->combosref].scriptname); ret = -10000;
9175 }
9176 19038 break;
9177 }
9178
9179 //NEWCOMBO STRUCT
9180
2/4
✓ Branch 0 taken 116988 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 116988 times.
116988 case COMBODTILE: GET_COMBO_VAR_DWORD(tile); break; //word
9181
2/4
✓ Branch 0 taken 112420 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 112420 times.
112420 case COMBODOTILE: GET_COMBO_VAR_DWORD(o_tile); break; //word
9182 case COMBODFRAME: GET_COMBO_VAR_BYTE(cur_frame); break; //char
9183 case COMBODACLK: GET_COMBO_VAR_BYTE(aclk); break; //char
9184 case COMBODASPEED: GET_COMBO_VAR_BYTE(speed); break; //char
9185
2/4
✓ Branch 0 taken 4546 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4546 times.
4546 case COMBODFLIP: GET_COMBO_VAR_BYTE(flip); break; //char
9186 case COMBODWALK:
9187 {
9188
2/4
✓ Branch 0 taken 6890 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6890 times.
6890 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9189 {
9190 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9191 ret = -10000;
9192 }
9193 else
9194 {
9195 6890 ret = ((combobuf[ri->combosref].walk&0x0F) *10000);
9196 }
9197 6890 break;
9198 }
9199 case COMBODEFFECT:
9200 {
9201
2/4
✓ Branch 0 taken 755 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 755 times.
755 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9202 {
9203 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9204 ret = -10000;
9205 }
9206 else
9207 {
9208 755 ret = (((combobuf[ri->combosref].walk&0xF0)>>4) *10000);
9209 }
9210 755 break;
9211 }
9212
2/4
✓ Branch 0 taken 5110 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5110 times.
5110 case COMBODTYPE: GET_COMBO_VAR_BYTE(type); break; //char
9213 case COMBODCSET:
9214 {
9215 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9216 {
9217 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9218 ret = -10000;
9219 }
9220 else
9221 {
9222 bool neg = combobuf[ri->combosref].csets&0x8;
9223 ret = ((combobuf[ri->combosref].csets&0x7) * (neg ? -10000 : 10000));
9224 }
9225 break;
9226 }
9227 case COMBODCSET2FLAGS:
9228 {
9229 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9230 {
9231 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9232 }
9233 else
9234 {
9235 ret = ((combobuf[ri->combosref].csets & 0xF0) >> 4) * 10000;
9236 }
9237 break;
9238 }
9239 case COMBODFOO: break; //W
9240
2/4
✓ Branch 0 taken 463074 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 463074 times.
463074 case COMBODATASCRIPT: GET_COMBO_VAR_DWORD(script); break; //W
9241 case COMBODFRAMES: GET_COMBO_VAR_BYTE(frames); break; //C
9242 case COMBODNEXTD: GET_COMBO_VAR_INT(nextcombo); break; //W
9243 case COMBODNEXTC: GET_COMBO_VAR_BYTE(nextcset); break; //C
9244 case COMBODFLAG: GET_COMBO_VAR_BYTE(flag); break; //C
9245 case COMBODSKIPANIM: GET_COMBO_VAR_BYTE(skipanim); break; //C
9246 case COMBODNEXTTIMER: GET_COMBO_VAR_DWORD(nexttimer); break; //W
9247 case COMBODAKIMANIMY: GET_COMBO_VAR_BYTE(skipanimy); break; //C
9248 case COMBODANIMFLAGS: GET_COMBO_VAR_BYTE(animflags); break; //C
9249 case COMBODEXPANSION: GET_COMBO_BYTE_INDEX(expansion, 6); break; //C , 6 INDICES
9250 case COMBODATTRIBUTES:
9251 {
9252 94 int32_t indx = ri->d[rINDEX] / 10000;
9253
2/4
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 94 times.
94 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9254 {
9255 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9256 ret = -10000;
9257 }
9258
2/4
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 94 times.
94 else if ( indx < 0 || indx > 4 )
9259 {
9260 scripting_log_error_with_context("Invalid Array Index: {}", indx);
9261 ret = -10000;
9262 }
9263 else
9264 {
9265 94 ret = (combobuf[ri->combosref].attributes[indx]);
9266 }
9267 }
9268 94 break;
9269 //case COMBODATAINITD: GET_COMBO_VAR_INDEX(initd, "InitD[]", 2); break; //LONG, 4 INDICES, INDIVIDUAL VALUES
9270 case COMBODATAINITD:
9271 {
9272 7891 int32_t indx = ri->d[rINDEX] / 10000;
9273
2/4
✓ Branch 0 taken 7891 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7891 times.
7891 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9274 {
9275 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9276 ret = -10000;
9277 }
9278
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7891 times.
7891 else if ( ((unsigned)indx) > 8 )
9279 {
9280 scripting_log_error_with_context("Invalid Array Index: {}", indx);
9281 ret = -10000;
9282 }
9283 else
9284 {
9285 7891 ret = (combobuf[ri->combosref].initd[indx] * (get_qr(qr_COMBODATA_INITD_MULT_TENK) ? 10000 : 1));
9286 }
9287 7891 break;
9288 }
9289
4/8
✓ Branch 0 taken 17628 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17628 times.
✓ Branch 4 taken 17628 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 17628 times.
35256 case COMBODATTRIBYTES: GET_COMBO_VAR_INDEX(attribytes, 8); break; //LONG, 4 INDICES, INDIVIDUAL VALUES
9290
4/8
✓ Branch 0 taken 136 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 136 times.
✓ Branch 4 taken 136 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 136 times.
272 case COMBODATTRISHORTS: GET_COMBO_VAR_INDEX(attrishorts, 8); break; //LONG, 4 INDICES, INDIVIDUAL VALUES
9291 case COMBODUSRFLAGARR:
9292 {
9293 13556 int32_t indx = ri->d[rINDEX] / 10000;
9294
2/4
✓ Branch 0 taken 13556 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 13556 times.
13556 if (ri->combosref < 0 || ri->combosref >(MAXCOMBOS - 1))
9295 {
9296 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9297 ret = 0;
9298 }
9299
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13556 times.
13556 else if (((unsigned)indx) > 15)
9300 {
9301 scripting_log_error_with_context("Invalid Array Index: {}", indx);
9302 ret = 0;
9303 }
9304 else
9305 {
9306 13556 ret = (combobuf[ri->combosref].usrflags & 1 << indx) ? 10000L : 0L;
9307 }
9308 13556 break;
9309 }
9310 case COMBODGENFLAGARR:
9311 {
9312 int32_t indx = ri->d[rINDEX] / 10000;
9313 if (ri->combosref < 0 || ri->combosref >(MAXCOMBOS - 1))
9314 {
9315 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9316 ret = 0;
9317 }
9318 else if (((unsigned)indx) > 1)
9319 {
9320 scripting_log_error_with_context("Invalid Array Index: {}", indx);
9321 ret = 0;
9322 }
9323 else
9324 {
9325 ret = (combobuf[ri->combosref].genflags & (1 << indx)) ? 10000L : 0L;
9326 }
9327 break;
9328 }
9329
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
18 case COMBODUSRFLAGS: GET_COMBO_VAR_INT(usrflags); break; //LONG
9330 case COMBODTRIGGERFLAGS: GET_COMBO_VAR_INDEX(triggerflags, 6); break; //LONG 3 INDICES AS FLAGSETS
9331 case COMBODTRIGGERFLAGS2:
9332 {
9333 3199 int32_t indx = ri->d[rINDEX] / 10000;
9334 3199 ret = -10000;
9335
2/4
✓ Branch 0 taken 3199 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3199 times.
3199 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9336 {
9337 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9338 }
9339
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3199 times.
3199 else if ( unsigned(indx) >= 32*6 )
9340 {
9341 scripting_log_error_with_context("Invalid Array Index: {}", indx);
9342 }
9343 else
9344 {
9345 3199 ret = (combobuf[ri->combosref].triggerflags[indx/32] & (1<<indx%32)) ? 10000L : 0L;
9346 }
9347 3199 break;
9348 }
9349 case COMBODTRIGGERBUTTON:
9350 {
9351 int32_t indx = ri->d[rINDEX] / 10000;
9352 ret = -10000;
9353 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9354 {
9355 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9356 }
9357 else if ( unsigned(indx) >= 8 )
9358 {
9359 scripting_log_error_with_context("Invalid Array Index: {}", indx);
9360 }
9361 else
9362 {
9363 ret = (combobuf[ri->combosref].triggerbtn & (1<<indx)) ? 10000L : 0L;
9364 }
9365 break;
9366 }
9367 case COMBODTRIGGERITEM:
9368 {
9369 ret = -10000;
9370 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9371 {
9372 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9373 }
9374 else ret = (combobuf[ri->combosref].triggeritem) * 10000;
9375 break;
9376 }
9377 case COMBODTRIGGERTIMER:
9378 {
9379 ret = -10000;
9380 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9381 {
9382 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9383 }
9384 else ret = (combobuf[ri->combosref].trigtimer) * 10000;
9385 break;
9386 }
9387 case COMBODTRIGGERSFX:
9388 {
9389 ret = -10000;
9390 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9391 {
9392 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9393 }
9394 else ret = (combobuf[ri->combosref].trigsfx) * 10000;
9395 break;
9396 }
9397 case COMBODTRIGGERCHANGECMB:
9398 {
9399 ret = -10000;
9400 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9401 {
9402 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9403 }
9404 else ret = (combobuf[ri->combosref].trigchange) * 10000;
9405 break;
9406 }
9407 case COMBODTRIGGERPROX:
9408 {
9409 ret = -10000;
9410 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9411 {
9412 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9413 }
9414 else ret = (combobuf[ri->combosref].trigprox) * 10000;
9415 break;
9416 }
9417 case COMBODTRIGGERLIGHTBEAM:
9418 {
9419 ret = -10000;
9420 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9421 {
9422 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9423 }
9424 else ret = (combobuf[ri->combosref].triglbeam) * 10000;
9425 break;
9426 }
9427 case COMBODTRIGGERCTR:
9428 {
9429 ret = -10000;
9430 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9431 {
9432 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9433 }
9434 else ret = (combobuf[ri->combosref].trigctr) * 10000;
9435 break;
9436 }
9437 case COMBODTRIGGERCTRAMNT:
9438 {
9439 ret = -10000;
9440 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9441 {
9442 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9443 }
9444 else ret = (combobuf[ri->combosref].trigctramnt) * 10000;
9445 break;
9446 }
9447 case COMBODTRIGGERCOOLDOWN:
9448 {
9449 ret = -10000;
9450 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9451 {
9452 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9453 }
9454 else ret = (combobuf[ri->combosref].trigcooldown) * 10000;
9455 break;
9456 }
9457 case COMBODTRIGGERCOPYCAT:
9458 {
9459 ret = -10000;
9460 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9461 {
9462 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9463 }
9464 else ret = (combobuf[ri->combosref].trigcopycat) * 10000;
9465 break;
9466 }
9467 case COMBODTRIGITEMPICKUP:
9468 {
9469 ret = -10000;
9470 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9471 {
9472 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9473 }
9474 else ret = (combobuf[ri->combosref].spawnip) * 10000;
9475 break;
9476 }
9477 case COMBODTRIGEXSTATE:
9478 {
9479 ret = -10000;
9480 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9481 {
9482 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9483 }
9484 else ret = (combobuf[ri->combosref].exstate) * 10000;
9485 break;
9486 }
9487 case COMBODTRIGEXDOORDIR:
9488 {
9489 ret = -10000;
9490 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9491 {
9492 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9493 }
9494 else ret = (combobuf[ri->combosref].exdoor_dir) * 10000;
9495 break;
9496 }
9497 case COMBODTRIGEXDOORIND:
9498 {
9499 ret = -10000;
9500 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9501 {
9502 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9503 }
9504 else ret = (combobuf[ri->combosref].exdoor_ind) * 10000;
9505 break;
9506 }
9507 case COMBODTRIGSPAWNENEMY:
9508 {
9509 ret = -10000;
9510 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9511 {
9512 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9513 }
9514 else ret = (combobuf[ri->combosref].spawnenemy) * 10000;
9515 break;
9516 }
9517 case COMBODTRIGSPAWNITEM:
9518 {
9519 25 ret = -10000;
9520
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 25 times.
25 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9521 {
9522 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9523 }
9524 25 else ret = (combobuf[ri->combosref].spawnitem) * 10000;
9525 25 break;
9526 }
9527 case COMBODTRIGCSETCHANGE:
9528 {
9529 ret = -10000;
9530 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9531 {
9532 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9533 }
9534 else ret = (combobuf[ri->combosref].trigcschange) * 10000;
9535 break;
9536 }
9537 case COMBODTRIGLITEMS:
9538 {
9539 ret = -10000;
9540 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9541 {
9542 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9543 }
9544 else ret = (combobuf[ri->combosref].trig_levelitems) * 10000;
9545 break;
9546 }
9547 case COMBODTRIGDMAPLVL:
9548 {
9549 ret = -10000;
9550 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9551 {
9552 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9553 }
9554 else ret = (combobuf[ri->combosref].trigdmlevel) * 10000;
9555 break;
9556 }
9557 case COMBODTRIGTINTR:
9558 {
9559 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9560 {
9561 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9562 break;
9563 }
9564 else ret = scripting_read_pal_color(combobuf[ri->combosref].trigtint[0]) * 10000;
9565 break;
9566 }
9567 case COMBODTRIGTINTG:
9568 {
9569 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9570 {
9571 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9572 }
9573 else ret = scripting_read_pal_color(combobuf[ri->combosref].trigtint[1]) * 10000;
9574 break;
9575 }
9576 case COMBODTRIGTINTB:
9577 {
9578 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9579 {
9580 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9581 }
9582 else ret = scripting_read_pal_color(combobuf[ri->combosref].trigtint[2]) * 10000;
9583 break;
9584 }
9585 case COMBODTRIGLVLPAL:
9586 {
9587 ret = -10000;
9588 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9589 {
9590 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9591 }
9592 else ret = 10000 * combobuf[ri->combosref].triglvlpalette;
9593 break;
9594 }
9595 case COMBODTRIGBOSSPAL:
9596 {
9597 ret = -10000;
9598 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9599 {
9600 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9601 }
9602 else ret = 10000 * combobuf[ri->combosref].trigbosspalette;
9603 break;
9604 }
9605 case COMBODTRIGQUAKETIME:
9606 {
9607 ret = -10000;
9608 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9609 {
9610 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9611 }
9612 else ret = 10000 * combobuf[ri->combosref].trigquaketime;
9613 break;
9614 }
9615 case COMBODTRIGWAVYTIME:
9616 {
9617 ret = -10000;
9618 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9619 {
9620 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9621 }
9622 else ret = 10000 * combobuf[ri->combosref].trigwavytime;
9623 break;
9624 }
9625 case COMBODTRIGSWORDJINX:
9626 {
9627 ret = -10000;
9628 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9629 {
9630 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9631 }
9632 else ret = 10000 * combobuf[ri->combosref].trig_swjinxtime;
9633 break;
9634 }
9635 case COMBODTRIGITEMJINX:
9636 {
9637 ret = -10000;
9638 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9639 {
9640 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9641 }
9642 else ret = 10000 * combobuf[ri->combosref].trig_itmjinxtime;
9643 break;
9644 }
9645 case COMBODTRIGSHIELDJINX:
9646 {
9647 ret = -10000;
9648 if (ri->combosref < 0 || ri->combosref >(MAXCOMBOS - 1))
9649 {
9650 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9651 }
9652 else ret = 10000 * combobuf[ri->combosref].trig_shieldjinxtime;
9653 break;
9654 }
9655 case COMBODTRIGSTUN:
9656 {
9657 ret = -10000;
9658 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9659 {
9660 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9661 }
9662 else ret = 10000 * combobuf[ri->combosref].trig_stuntime;
9663 break;
9664 }
9665 case COMBODTRIGBUNNY:
9666 {
9667 ret = -10000;
9668 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9669 {
9670 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9671 }
9672 else ret = 10000 * combobuf[ri->combosref].trig_bunnytime;
9673 break;
9674 }
9675 case COMBODTRIGPUSHTIME:
9676 {
9677 ret = -10000;
9678 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9679 {
9680 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9681 }
9682 else ret = 10000 * combobuf[ri->combosref].trig_pushtime;
9683 break;
9684 }
9685 case COMBODLIFTGFXCOMBO:
9686 {
9687 ret = -10000;
9688 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9689 {
9690 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9691 }
9692 else ret = (combobuf[ri->combosref].liftcmb) * 10000;
9693 break;
9694 }
9695 case COMBODLIFTGFXCCSET:
9696 {
9697 ret = -10000;
9698 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9699 {
9700 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9701 }
9702 else ret = (combobuf[ri->combosref].liftcs) * 10000;
9703 break;
9704 }
9705 case COMBODLIFTUNDERCMB:
9706 {
9707 ret = -10000;
9708 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9709 {
9710 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9711 }
9712 else ret = (combobuf[ri->combosref].liftundercmb) * 10000;
9713 break;
9714 }
9715 case COMBODLIFTUNDERCS:
9716 {
9717 ret = -10000;
9718 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9719 {
9720 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9721 }
9722 else ret = (combobuf[ri->combosref].liftundercs) * 10000;
9723 break;
9724 }
9725 case COMBODLIFTDAMAGE:
9726 {
9727 ret = -10000;
9728 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9729 {
9730 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9731 }
9732 else ret = (combobuf[ri->combosref].liftdmg) * 10000;
9733 break;
9734 }
9735 case COMBODLIFTLEVEL:
9736 {
9737 ret = -10000;
9738 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9739 {
9740 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9741 }
9742 else ret = (combobuf[ri->combosref].liftlvl) * 10000;
9743 break;
9744 }
9745 case COMBODLIFTITEM:
9746 {
9747 ret = -10000;
9748 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9749 {
9750 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9751 }
9752 else ret = (combobuf[ri->combosref].liftitm) * 10000;
9753 break;
9754 }
9755 case COMBODLIFTFLAGS:
9756 {
9757 ret = -10000;
9758 int32_t indx = ri->d[rINDEX] / 10000;
9759 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9760 {
9761 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9762 break;
9763 }
9764 if ( unsigned(indx) > 7 )
9765 {
9766 scripting_log_error_with_context("Invalid index: {}", indx);
9767 break;
9768 }
9769 ret = (combobuf[ri->combosref].liftflags & (1<<indx)) ? 10000 : 0;
9770 break;
9771 }
9772 case COMBODLIFTGFXTYPE:
9773 {
9774 ret = -10000;
9775 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9776 {
9777 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9778 }
9779 else ret = (combobuf[ri->combosref].liftgfx) * 10000;
9780 break;
9781 }
9782 case COMBODLIFTGFXSPRITE:
9783 {
9784 ret = -10000;
9785 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9786 {
9787 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9788 }
9789 else ret = (combobuf[ri->combosref].liftsprite) * 10000;
9790 break;
9791 }
9792 case COMBODLIFTSFX:
9793 {
9794 ret = -10000;
9795 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9796 {
9797 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9798 }
9799 else ret = (combobuf[ri->combosref].liftsfx) * 10000;
9800 break;
9801 }
9802 case COMBODLIFTBREAKSPRITE:
9803 {
9804 ret = -10000;
9805 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9806 {
9807 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9808 }
9809 else ret = (combobuf[ri->combosref].liftbreaksprite) * 10000;
9810 break;
9811 }
9812 case COMBODLIFTBREAKSFX:
9813 {
9814 ret = -10000;
9815 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9816 {
9817 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9818 }
9819 else ret = (combobuf[ri->combosref].liftbreaksfx) * 10000;
9820 break;
9821 }
9822 case COMBODLIFTHEIGHT:
9823 {
9824 ret = -10000;
9825 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9826 {
9827 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9828 }
9829 else ret = (combobuf[ri->combosref].lifthei) * 10000;
9830 break;
9831 }
9832 case COMBODLIFTTIME:
9833 {
9834 ret = -10000;
9835 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9836 {
9837 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9838 }
9839 else ret = (combobuf[ri->combosref].lifttime) * 10000;
9840 break;
9841 }
9842 case COMBODLIFTLIGHTRAD:
9843 {
9844 ret = -10000;
9845 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9846 {
9847 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9848 }
9849 else ret = (combobuf[ri->combosref].liftlightrad) * 10000;
9850 break;
9851 }
9852 case COMBODLIFTLIGHTSHAPE:
9853 {
9854 ret = -10000;
9855 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9856 {
9857 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9858 }
9859 else ret = (combobuf[ri->combosref].liftlightshape) * 10000;
9860 break;
9861 }
9862 case COMBODLIFTWEAPONITEM:
9863 {
9864 ret = -10000;
9865 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9866 {
9867 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9868 }
9869 else ret = (combobuf[ri->combosref].lift_parent_item) * 10000;
9870 break;
9871 }
9872 case COMBODTRIGGERLSTATE:
9873 {
9874 ret = -10000;
9875 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9876 {
9877 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9878 }
9879 else ret = (combobuf[ri->combosref].trig_lstate) * 10000;
9880 break;
9881 }
9882 case COMBODTRIGGERGSTATE:
9883 {
9884 ret = -10000;
9885 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9886 {
9887 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9888 }
9889 else ret = (combobuf[ri->combosref].trig_gstate) * 10000;
9890 break;
9891 }
9892 case COMBODTRIGGERGROUP:
9893 {
9894 ret = -10000;
9895 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9896 {
9897 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9898 }
9899 else ret = (combobuf[ri->combosref].trig_group) * 10000;
9900 break;
9901 }
9902 case COMBODTRIGGERGROUPVAL:
9903 {
9904 ret = -10000;
9905 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9906 {
9907 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9908 }
9909 else ret = (combobuf[ri->combosref].trig_group_val) * 10000;
9910 break;
9911 }
9912 case COMBODTRIGGERGTIMER:
9913 {
9914 ret = -10000;
9915 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9916 {
9917 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9918 }
9919 else ret = (combobuf[ri->combosref].trig_statetime) * 10000;
9920 break;
9921 }
9922 case COMBODTRIGGERGENSCRIPT:
9923 {
9924 ret = -10000;
9925 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
9926 {
9927 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
9928 }
9929 else ret = (combobuf[ri->combosref].trig_genscr) * 10000;
9930 break;
9931 }
9932
9933 case COMBODTRIGGERLEVEL: GET_COMBO_VAR_INT(triggerlevel); break; //LONG
9934 11602 case COMBODATAID: ret = (ri->combosref*10000); break;
9935 //COMBOCLASS STRUCT
9936 //case COMBODNAME: //CHAR[64], STRING
9937 case COMBODBLOCKNPC: GET_COMBOCLASS_VAR_BYTE(block_enemies); break; //C
9938 case COMBODBLOCKHOLE: GET_COMBOCLASS_VAR_BYTE(block_hole); break; //C
9939 case COMBODBLOCKTRIG: GET_COMBOCLASS_VAR_BYTE(block_trigger); break; //C
9940 case COMBODBLOCKWEAPON: GET_COMBOCLASS_BYTE_INDEX(block_weapon, 32); break; //C, 32 INDICES
9941 case COMBODCONVXSPEED: GET_COMBOCLASS_VAR_DWORD(conveyor_x_speed); break; //SHORT
9942 case COMBODCONVYSPEED: GET_COMBOCLASS_VAR_DWORD(conveyor_y_speed); break; //SHORT
9943 case COMBODSPAWNNPC: GET_COMBOCLASS_VAR_DWORD(create_enemy); break; //W
9944 case COMBODSPAWNNPCWHEN: GET_COMBOCLASS_VAR_BYTE(create_enemy_when); break; //C
9945 case COMBODSPAWNNPCCHANGE: GET_COMBOCLASS_VAR_INT(create_enemy_change); break; //LONG
9946 case COMBODDIRCHANGETYPE: GET_COMBOCLASS_VAR_BYTE(directional_change_type); break; //C
9947 case COMBODDISTANCECHANGETILES: GET_COMBOCLASS_VAR_INT(distance_change_tiles); break; //LONG
9948 case COMBODDIVEITEM: GET_COMBOCLASS_VAR_DWORD(dive_item); break; //SHORT
9949 case COMBODDOCK: GET_COMBOCLASS_VAR_BYTE(dock); break; //C
9950 case COMBODFAIRY: GET_COMBOCLASS_VAR_BYTE(fairy); break; //C
9951 case COMBODFFATTRCHANGE: GET_COMBOCLASS_VAR_BYTE(ff_combo_attr_change); break; //C
9952 case COMBODFOORDECOTILE: GET_COMBOCLASS_VAR_INT(foot_decorations_tile); break; //LONG
9953 case COMBODFOORDECOTYPE: GET_COMBOCLASS_VAR_BYTE(foot_decorations_type); break; //C
9954 case COMBODHOOKSHOTPOINT: GET_COMBOCLASS_VAR_BYTE(hookshot_grab_point); break; //C
9955 case COMBODLADDERPASS: GET_COMBOCLASS_VAR_BYTE(ladder_pass); break; //C
9956 case COMBODLOCKBLOCK: GET_COMBOCLASS_VAR_BYTE(lock_block_type); break; //C
9957 case COMBODLOCKBLOCKCHANGE: GET_COMBOCLASS_VAR_INT(lock_block_change); break; //LONG
9958 case COMBODMAGICMIRROR: GET_COMBOCLASS_VAR_BYTE(magic_mirror_type); break; //C
9959 case COMBODMODHPAMOUNT: GET_COMBOCLASS_VAR_DWORD(modify_hp_amount); break; //SHORT
9960 case COMBODMODHPDELAY: GET_COMBOCLASS_VAR_BYTE(modify_hp_delay); break; //C
9961 case COMBODMODHPTYPE: GET_COMBOCLASS_VAR_BYTE(modify_hp_type); break; //C
9962 case COMBODNMODMPAMOUNT: GET_COMBOCLASS_VAR_DWORD(modify_mp_amount); break; //SHORT
9963 case COMBODMODMPDELAY: GET_COMBOCLASS_VAR_BYTE(modify_mp_delay); break; //C
9964 case COMBODMODMPTYPE: GET_COMBOCLASS_VAR_BYTE(modify_mp_type); break; //C
9965 case COMBODNOPUSHBLOCK: GET_COMBOCLASS_VAR_BYTE(no_push_blocks); break; //C
9966 case COMBODOVERHEAD: GET_COMBOCLASS_VAR_BYTE(overhead); break; //C
9967 case COMBODPLACENPC: GET_COMBOCLASS_VAR_BYTE(place_enemy); break; //C
9968 case COMBODPUSHDIR: GET_COMBOCLASS_VAR_BYTE(push_direction); break; //C
9969 case COMBODPUSHWAIT: GET_COMBOCLASS_VAR_BYTE(push_wait); break; //C
9970 case COMBODPUSHHEAVY: GET_COMBOCLASS_VAR_BYTE(push_weight); break; //C
9971 case COMBODPUSHED: GET_COMBOCLASS_VAR_BYTE(pushed); break; //C
9972 case COMBODRAFT: GET_COMBOCLASS_VAR_BYTE(raft); break; //C
9973 case COMBODRESETROOM: GET_COMBOCLASS_VAR_BYTE(reset_room); break; //C
9974 case COMBODSAVEPOINTTYPE: GET_COMBOCLASS_VAR_BYTE(save_point_type); break; //C
9975 case COMBODSCREENFREEZETYPE: GET_COMBOCLASS_VAR_BYTE(screen_freeze_type); break; //C
9976 case COMBODSECRETCOMBO: GET_COMBOCLASS_VAR_BYTE(secret_combo); break; //C
9977 case COMBODSINGULAR: GET_COMBOCLASS_VAR_BYTE(singular); break; //C
9978 case COMBODSLOWWALK: GET_COMBOCLASS_VAR_BYTE(slow_movement); break; //C
9979 case COMBODSTATUETYPE: GET_COMBOCLASS_VAR_BYTE(statue_type); break; //C
9980 case COMBODSTEPTYPE: GET_COMBOCLASS_VAR_BYTE(step_type); break; //C
9981 case COMBODSTEPCHANGEINTO: GET_COMBOCLASS_VAR_INT(step_change_to); break; //LONG
9982 case COMBODSTRIKEWEAPONS: GET_COMBOCLASS_BYTE_INDEX(strike_weapons, 32); break; //BYTE, 32 INDICES.
9983 case COMBODSTRIKEREMNANTS: GET_COMBOCLASS_VAR_INT(strike_remnants); break; //LONG
9984 case COMBODSTRIKEREMNANTSTYPE: GET_COMBOCLASS_VAR_BYTE(strike_remnants_type); break; //C
9985 case COMBODSTRIKECHANGE: GET_COMBOCLASS_VAR_INT(strike_change); break; //LONG
9986 case COMBODSTRIKEITEM: GET_COMBOCLASS_VAR_DWORD(strike_item); break; //SHORT
9987 case COMBODTOUCHITEM: GET_COMBOCLASS_VAR_DWORD(touch_item); break; //SHORT
9988 case COMBODTOUCHSTAIRS: GET_COMBOCLASS_VAR_BYTE(touch_stairs); break; //C
9989 case COMBODTRIGGERTYPE: GET_COMBOCLASS_VAR_BYTE(trigger_type); break; //C
9990 case COMBODTRIGGERSENS: GET_COMBOCLASS_VAR_BYTE(trigger_sensitive); break; //C
9991 case COMBODWARPTYPE: GET_COMBOCLASS_VAR_BYTE(warp_type); break; //C
9992 case COMBODWARPSENS: GET_COMBOCLASS_VAR_BYTE(warp_sensitive); break; //C
9993 case COMBODWARPDIRECT: GET_COMBOCLASS_VAR_BYTE(warp_direct); break; //C
9994 case COMBODWARPLOCATION: GET_COMBOCLASS_VAR_BYTE(warp_location); break; //C
9995 case COMBODWATER: GET_COMBOCLASS_VAR_BYTE(water); break; //C
9996 case COMBODWHISTLE: GET_COMBOCLASS_VAR_BYTE(whistle); break; //C
9997 case COMBODWINGAME: GET_COMBOCLASS_VAR_BYTE(win_game); break; //C
9998 case COMBODBLOCKWPNLEVEL: GET_COMBOCLASS_VAR_BYTE(block_weapon_lvl); break; //C
9999
10000
10001
10002 ///----------------------------------------------------------------------------------------------------//
10003 //npcdata nd-> variables
10004
10005 //npcdata nd->member variable
10006 #define GET_NPCDATA_VAR_INT32(member, str) \
10007 { \
10008 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
10009 { \
10010 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", str, (ri->npcdataref*10000)); \
10011 ret = -10000; \
10012 } \
10013 else \
10014 { \
10015 ret = (guysbuf[ri->npcdataref].member *10000); \
10016 } \
10017 } \
10018
10019 #define GET_NPCDATA_VAR_BYTE(member, str) \
10020 { \
10021 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
10022 { \
10023 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", str, (ri->npcdataref*10000)); \
10024 ret = -10000; \
10025 } \
10026 else \
10027 { \
10028 ret = (guysbuf[ri->npcdataref].member *10000); \
10029 } \
10030 } \
10031
10032 #define GET_NPCDATA_VAR_INT16(member, str) \
10033 { \
10034 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
10035 { \
10036 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", str, (ri->npcdataref*10000)); \
10037 ret = -10000; \
10038 } \
10039 else \
10040 { \
10041 ret = (guysbuf[ri->npcdataref].member *10000); \
10042 } \
10043 } \
10044
10045 #define GET_NPCDATA_VAR_INDEX(member, str, indexbound) \
10046 { \
10047 int32_t indx = ri->d[rINDEX] / 10000; \
10048 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
10049 { \
10050 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", str, (ri->npcdataref*10000)); \
10051 ret = -10000; \
10052 } \
10053 else if ( (unsigned)indx > indexbound ) \
10054 { \
10055 Z_scripterrlog("Invalid Array Index passed to npcdata->%s: %d\n", str, indx); \
10056 ret = -10000; \
10057 } \
10058 else \
10059 { \
10060 ret = (guysbuf[ri->npcdataref].member[indx] * 10000); \
10061 } \
10062 }
10063
10064 #define GET_NPCDATA_BYTE_INDEX(member, str, indexbound) \
10065 { \
10066 int32_t indx = ri->d[rINDEX] / 10000; \
10067 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
10068 { \
10069 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", str, (ri->npcdataref*10000)); \
10070 ret = -10000; \
10071 } \
10072 else if ( (unsigned)indx > indexbound ) \
10073 { \
10074 Z_scripterrlog("Invalid Array Index passed to npcdata->%s: %d\n", str, indx); \
10075 ret = -10000; \
10076 } \
10077 else \
10078 { \
10079 ret = (guysbuf[ri->npcdataref].member[indx] * 100000); \
10080 } \
10081 }
10082
10083 #define GET_NPCDATA_FLAG(member, str, indexbound) \
10084 { \
10085 int32_t flag = (value/10000); \
10086 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
10087 { \
10088 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", str, (ri->npcdataref*10000)); \
10089 } \
10090 else \
10091 { \
10092 ret = (guysbuf[ID].member&flag) ? 10000 : 0); \
10093 } \
10094 } \
10095
10096 // These are for compat only, though seemingly no quests even use these.
10097 case NPCDATAFLAGS1:
10098 {
10099 if( (unsigned) ri->npcdataref > (MAXNPCS-1) )
10100 {
10101 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", "Flags (deprecated)", (ri->npcdataref*10000));
10102 ret = -10000;
10103 }
10104 else
10105 {
10106 uint32_t value = guysbuf[ri->npcdataref].flags & 0xFFFFFFFFLL;
10107 ret = value * 10000;
10108 }
10109 }
10110 break;
10111 case NPCDATAFLAGS2:
10112 {
10113 if( (unsigned) ri->npcdataref > (MAXNPCS-1) )
10114 {
10115 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", "Flags2 (deprecated)", (ri->npcdataref*10000));
10116 ret = -10000;
10117 }
10118 else
10119 {
10120 uint32_t value = (guysbuf[ri->npcdataref].flags >> 32) & 0xFFFFFFFFLL;
10121 ret = value * 10000;
10122 }
10123 }
10124 break;
10125
10126 case NPCDATATILE: GET_NPCDATA_VAR_BYTE(tile, "Tile"); break;
10127 case NPCDATAWIDTH: GET_NPCDATA_VAR_BYTE(width, "Width"); break;
10128 case NPCDATAHEIGHT: GET_NPCDATA_VAR_BYTE(height, "Height"); break;
10129 case NPCDATASTILE: GET_NPCDATA_VAR_BYTE(s_tile, "STile"); break;
10130 case NPCDATASWIDTH: GET_NPCDATA_VAR_BYTE(s_width, "SWidth"); break;
10131 case NPCDATASHEIGHT: GET_NPCDATA_VAR_BYTE(s_height, "SHeight"); break;
10132
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3182 times.
3182 case NPCDATAETILE: GET_NPCDATA_VAR_INT32(e_tile, "ExTile"); break;
10133 case NPCDATAEWIDTH: GET_NPCDATA_VAR_BYTE(e_width, "ExWidth"); break;
10134 case NPCDATAEHEIGHT: GET_NPCDATA_VAR_BYTE(e_height, "ExHeight"); break;
10135 case NPCDATAHP: GET_NPCDATA_VAR_INT16(hp, "HP"); break;
10136 case NPCDATAFAMILY: GET_NPCDATA_VAR_INT16(family, "Family"); break;
10137
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3182 times.
3182 case NPCDATACSET: GET_NPCDATA_VAR_INT16(cset, "CSet"); break;
10138 case NPCDATAANIM: GET_NPCDATA_VAR_INT16(anim, "Anim"); break;
10139 case NPCDATAEANIM: GET_NPCDATA_VAR_INT16(e_anim, "ExAnim"); break;
10140 case NPCDATAFRAMERATE: GET_NPCDATA_VAR_INT16(frate, "Framerate"); break;
10141 case NPCDATAEFRAMERATE: GET_NPCDATA_VAR_INT16(e_frate, "ExFramerate"); break;
10142 case NPCDATATOUCHDAMAGE: GET_NPCDATA_VAR_INT16(dp, "TouchDamage"); break;
10143 case NPCDATAWEAPONDAMAGE: GET_NPCDATA_VAR_INT16(wdp, "WeaponDamage"); break;
10144 case NPCDATAWEAPON: GET_NPCDATA_VAR_INT16(weapon, "Weapon"); break;
10145 case NPCDATARANDOM: GET_NPCDATA_VAR_INT16(rate, "Random"); break;
10146 case NPCDATAHALT: GET_NPCDATA_VAR_INT16(hrate, "Haltrate"); break;
10147 case NPCDATASTEP: GET_NPCDATA_VAR_INT16(step, "Step"); break;
10148 case NPCDATAHOMING: GET_NPCDATA_VAR_INT16(homing, "Homing"); break;
10149 case NPCDATAHUNGER: GET_NPCDATA_VAR_INT16(grumble, "Hunger"); break;
10150 case NPCDATADROPSET: GET_NPCDATA_VAR_INT16(item_set, "Dropset"); break;
10151 case NPCDATABGSFX: GET_NPCDATA_VAR_INT16(bgsfx, "BGSFX"); break;
10152 case NPCDATADEATHSFX: GET_NPCDATA_VAR_BYTE(deadsfx, "DeathSFX"); break;
10153
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 case NPCDATAHITSFX: GET_NPCDATA_VAR_BYTE(hitsfx, "HitSFX"); break;
10154 case NPCDATAXOFS: GET_NPCDATA_VAR_INT32(xofs, "DrawXOffset"); break;
10155 case NPCDATAYOFS: GET_NPCDATA_VAR_INT32(yofs, "DrawYOffset"); break;
10156 case NPCDATAZOFS: GET_NPCDATA_VAR_INT32(zofs, "DrawZOffset"); break;
10157 case NPCDATAHXOFS: GET_NPCDATA_VAR_INT32(hxofs, "HitXOffset"); break;
10158 case NPCDATAHYOFS: GET_NPCDATA_VAR_INT32(hyofs, "HitYOffset"); break;
10159 case NPCDATAHITWIDTH: GET_NPCDATA_VAR_INT32(hxsz, "HitWidth"); break;
10160 case NPCDATAHITHEIGHT: GET_NPCDATA_VAR_INT32(hysz, "HitHeight"); break;
10161 case NPCDATAHITZ: GET_NPCDATA_VAR_INT32(hzsz, "HitZHeight"); break;
10162 case NPCDATASCRIPT: GET_NPCDATA_VAR_INT32(script, "Script"); break;
10163 case NPCDATATILEWIDTH: GET_NPCDATA_VAR_INT32(txsz, "TileWidth"); break;
10164 case NPCDATATILEHEIGHT: GET_NPCDATA_VAR_INT32(tysz, "TileHeight"); break;
10165 case NPCDATAWPNSPRITE: GET_NPCDATA_VAR_INT32(wpnsprite, "WeaponSprite"); break;
10166 case NPCDATAWEAPONSCRIPT: GET_NPCDATA_VAR_INT32(weaponscript, "WeaponScript"); break;
10167 case NPCDATADEFENSE: GET_NPCDATA_VAR_INDEX(defense, "Defense", 42); break;
10168 case NPCDATAINITD: GET_NPCDATA_VAR_INDEX(initD, "InitD", 8); break;
10169 case NPCDATAWEAPONINITD: GET_NPCDATA_VAR_INDEX(weap_initiald, "WeaponInitD", 8); break;
10170 case NPCDATASIZEFLAG: GET_NPCDATA_VAR_INT32(SIZEflags, "SizeFlags"); break;
10171
10172 case NPCDATAFROZENTILE: GET_NPCDATA_VAR_INT32(frozentile, "FrozenTile"); break;
10173 case NPCDATAFROZENCSET: GET_NPCDATA_VAR_INT32(frozencset, "FrozenCSet"); break;
10174 case NPCDATAFIRESFX: GET_NPCDATA_VAR_BYTE(firesfx, "WeaponSFX"); break;
10175
10176 case NPCDATAATTRIBUTE:
10177 {
10178 int32_t indx = ri->d[rINDEX] / 10000;
10179 if(ri->npcdataref > (MAXNPCS-1) )
10180 {
10181 Z_scripterrlog("Invalid Sprite ID passed to npcdata->Attributes[]: %d\n", (ri->npcdataref*10000));
10182 ret = -10000;
10183 }
10184 else if ( indx < 0 || indx >= MAX_NPC_ATTRIBUTES )
10185 {
10186 Z_scripterrlog("Invalid Array Index passed to npcdata->Attributes[]: %d\n", indx);
10187 ret = -10000;
10188 }
10189 else
10190 {
10191 ret = (guysbuf[ri->npcdataref].attributes[indx] * 10000);
10192 }
10193
10194 break;
10195 }
10196
10197 case NPCDATAFLAG:
10198 {
10199 int32_t indx = ri->d[rINDEX] / 10000;
10200 if(ri->npcdataref > (MAXNPCS-1) )
10201 {
10202 Z_scripterrlog("Invalid Sprite ID passed to npcdata->Flags[]: %d\n", (ri->npcdataref*10000));
10203 ret = -10000;
10204 }
10205 else if ( indx < 0 || indx >= MAX_NPC_FLAGS )
10206 {
10207 Z_scripterrlog("Invalid Array Index passed to npcdata->Flags[]: %d\n", indx);
10208 ret = -10000;
10209 }
10210 else
10211 {
10212 guy_flags bit = (guy_flags)(1<<indx);
10213 ret = (guysbuf[ri->npcdataref].flags&bit) * 10000;
10214 }
10215
10216 break;
10217 }
10218
10219 case NPCDATABEHAVIOUR:
10220 {
10221 if(ri->npcdataref > (MAXNPCS-1) )
10222 {
10223 ret = -10000;
10224 break;
10225 }
10226 int32_t index = vbound(ri->d[rINDEX]/10000,0,4);
10227 switch(index)
10228 {
10229 case 0:
10230 ret=(guysbuf[ri->npcdataref].editorflags & ENEMY_FLAG1)?10000:0; break;
10231 case 1:
10232 ret=(guysbuf[ri->npcdataref].editorflags & ENEMY_FLAG2)?10000:0; break;
10233 case 2:
10234 ret=(guysbuf[ri->npcdataref].editorflags & ENEMY_FLAG3)?10000:0; break;
10235 case 3:
10236 ret=(guysbuf[ri->npcdataref].editorflags & ENEMY_FLAG4)?10000:0; break;
10237 case 4:
10238 ret=(guysbuf[ri->npcdataref].editorflags & ENEMY_FLAG5)?10000:0; break;
10239 case 5:
10240 ret=(guysbuf[ri->npcdataref].editorflags & ENEMY_FLAG6)?10000:0; break;
10241 case 6:
10242 ret=(guysbuf[ri->npcdataref].editorflags & ENEMY_FLAG7)?10000:0; break;
10243 case 7:
10244 ret=(guysbuf[ri->npcdataref].editorflags & ENEMY_FLAG8)?10000:0; break;
10245 case 8:
10246 ret=(guysbuf[ri->npcdataref].editorflags & ENEMY_FLAG9)?10000:0; break;
10247 case 9:
10248 ret=(guysbuf[ri->npcdataref].editorflags & ENEMY_FLAG10)?10000:0; break;
10249 case 10:
10250 ret=(guysbuf[ri->npcdataref].editorflags & ENEMY_FLAG11)?10000:0; break;
10251 case 11:
10252 ret=(guysbuf[ri->npcdataref].editorflags & ENEMY_FLAG12)?10000:0; break;
10253 case 12:
10254 ret=(guysbuf[ri->npcdataref].editorflags & ENEMY_FLAG13)?10000:0; break;
10255 case 13:
10256 ret=(guysbuf[ri->npcdataref].editorflags & ENEMY_FLAG14)?10000:0; break;
10257 case 14:
10258 ret=(guysbuf[ri->npcdataref].editorflags & ENEMY_FLAG15)?10000:0; break;
10259 case 15:
10260 ret=(guysbuf[ri->npcdataref].editorflags & ENEMY_FLAG16)?10000:0; break;
10261
10262
10263 default:
10264 ret = 0; break;
10265 }
10266
10267 break;
10268 }
10269
10270 case NPCDATASHIELD:
10271 {
10272 int32_t indx = ri->d[rINDEX] / 10000;
10273 if(ri->npcdataref > (MAXNPCS-1) )
10274 {
10275 Z_scripterrlog("Invalid NPC ID passed to npcdata->Shield[]: %d\n", (ri->npcdataref*10000));
10276 ret = -10000;
10277 break;
10278 }
10279 else
10280 {
10281 switch(indx)
10282 {
10283 case 0:
10284 {
10285 ret = ((guysbuf[ri->npcdataref].flags&guy_shield_front) ? 10000 : 0);
10286 break;
10287 }
10288 case 1:
10289 {
10290 ret = ((guysbuf[ri->npcdataref].flags&guy_shield_left) ? 10000 : 0);
10291 break;
10292 }
10293 case 2:
10294 {
10295 ret = ((guysbuf[ri->npcdataref].flags&guy_shield_right) ? 10000 : 0);
10296 break;
10297 }
10298 case 3:
10299 {
10300 ret = ((guysbuf[ri->npcdataref].flags&guy_shield_back) ? 10000 : 0);
10301 break;
10302 }
10303 case 4:
10304 {
10305 ret = ((guysbuf[ri->npcdataref].flags&guy_bkshield) ? 10000 : 0);
10306 break;
10307 }
10308 default:
10309 {
10310 Z_scripterrlog("Invalid Array Index passed to npcdata->Shield[]: %d\n", indx);
10311 ret = -10000;
10312 break;
10313 }
10314 }
10315 }
10316 }
10317 break;
10318
10319 case NPCDSHADOWSPR:
10320 {
10321 if(ri->npcdataref > (MAXNPCS-1) )
10322 {
10323 Z_scripterrlog("Invalid NPC ID passed to npcdata->ShadowSprite: %d\n", (ri->npcdataref*10000));
10324 ret = -10000;
10325 }
10326 else
10327 {
10328 ret = guysbuf[ri->npcdataref].spr_shadow * 10000;
10329 }
10330 break;
10331 }
10332 case NPCDSPAWNSPR:
10333 {
10334 if(ri->npcdataref > (MAXNPCS-1) )
10335 {
10336 Z_scripterrlog("Invalid NPC ID passed to npcdata->SpawnSprite: %d\n", (ri->npcdataref*10000));
10337 ret = -10000;
10338 }
10339 else
10340 {
10341 ret = guysbuf[ri->npcdataref].spr_spawn * 10000;
10342 }
10343 break;
10344 }
10345 case NPCDDEATHSPR:
10346 {
10347 if(ri->npcdataref > (MAXNPCS-1) )
10348 {
10349 Z_scripterrlog("Invalid NPC ID passed to npcdata->DeathSprite: %d\n", (ri->npcdataref*10000));
10350 ret = -10000;
10351 }
10352 else
10353 {
10354 ret = guysbuf[ri->npcdataref].spr_death * 10000;
10355 }
10356 break;
10357 }
10358
10359 case NPCMATCHINITDLABEL: //Same form as SetScreenD()
10360 //bool npcdata->MatchInitDLabel("label", d)
10361 {
10362
10363 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
10364 {
10365 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", (ri->npcdataref*10000), "MatchInitDLabel()");
10366 ret = 0;
10367 break;
10368 }
10369
10370 int32_t arrayptr = get_register(sarg1) / 10000;
10371 int32_t init_d_index = get_register(sarg2) / 10000;
10372
10373 string name;
10374 ArrayH::getString(arrayptr, name, 256); // What's the limit on name length?
10375
10376 bool match = (!( strcmp(name.c_str(), guysbuf[ri->npcdataref].initD_label[init_d_index] )));
10377
10378 ret = ( match ? 10000 : 0 );
10379 break;
10380 }
10381
10382 ///----------------------------------------------------------------------------------------------------//
10383 //Dropset Variables
10384
10385 case DROPSETITEMS:
10386 {
10387 if(ri->dropsetref > MAXITEMDROPSETS)
10388 {
10389 Z_scripterrlog("Invalid dropset pointer %d\n", ri->dropsetref);
10390 ret = -10000;
10391 break;
10392 }
10393 int32_t indx = ri->d[rINDEX]/10000;
10394 if(indx < 0 || indx > 9)
10395 {
10396 Z_scripterrlog("Invalid index passed to dropdata->Items[]: %d\n", indx);
10397 ret = -10000;
10398 }
10399 else
10400 {
10401 ret = item_drop_sets[ri->dropsetref].item[indx] * 10000;
10402 }
10403 break;
10404 }
10405 case DROPSETCHANCES:
10406 {
10407 if(ri->dropsetref > MAXITEMDROPSETS)
10408 {
10409 Z_scripterrlog("Invalid dropset pointer %d\n", ri->dropsetref);
10410 ret = -10000;
10411 break;
10412 }
10413 int32_t indx = ri->d[rINDEX]/10000;
10414 if(indx < 0 || indx > 9)
10415 {
10416 Z_scripterrlog("Invalid index passed to dropdata->Chances[]: %d\n", indx);
10417 ret = -10000;
10418 }
10419 else
10420 {
10421 ret = item_drop_sets[ri->dropsetref].chance[indx+1] * 10000; //+1 is because '0' is 'nothing''s chance
10422 }
10423 break;
10424 }
10425 case DROPSETNULLCHANCE:
10426 {
10427 if(ri->dropsetref > MAXITEMDROPSETS)
10428 {
10429 Z_scripterrlog("Invalid dropset pointer %d\n", ri->dropsetref);
10430 ret = -10000;
10431 break;
10432 }
10433 ret = item_drop_sets[ri->dropsetref].chance[0] * 10000;
10434 break;
10435 }
10436 case DROPSETCHOOSE:
10437 {
10438
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(ri->dropsetref > MAXITEMDROPSETS)
10439 {
10440 Z_scripterrlog("Invalid dropset pointer %d\n", ri->dropsetref);
10441 ret = -10000;
10442 break;
10443 }
10444 10 ret = select_dropitem(ri->dropsetref) * 10000;
10445 10 break;
10446 }
10447
10448 ///----------------------------------------------------------------------------------------------------//
10449 //Audio Variables
10450
10451 case AUDIOVOLUME:
10452 {
10453 int32_t indx = ri->d[rINDEX] / 10000;
10454 switch(indx)
10455 {
10456
10457 case 0: //midi volume
10458 {
10459 ret = FFScript::do_getMIDI_volume() * 10000;
10460 break;
10461 }
10462 case 1: //digi volume
10463 {
10464 ret = FFScript::do_getDIGI_volume() * 10000;
10465 break;
10466 }
10467 case 2: //emh music volume
10468 {
10469 ret = FFScript::do_getMusic_volume() * 10000;
10470 break;
10471 }
10472 case 3: //sfx volume
10473 {
10474 ret = FFScript::do_getSFX_volume() * 10000;
10475 break;
10476 }
10477 default:
10478 {
10479 Z_scripterrlog("Attempted to access an invalid index of Audio->Volume[]", indx);
10480 ret = -10000;
10481 break;
10482 }
10483 }
10484 }
10485 break;
10486
10487 case AUDIOPAN:
10488 {
10489 ret = FFScript::do_getSFX_pan() * 10000;
10490 break;
10491 }
10492
10493 ///----------------------------------------------------------------------------------------------------//
10494 //Graphics->
10495
10496 case NUMDRAWS:
10497 ret = script_drawing_commands.Count() * 10000;
10498 //ret = FFCore.numscriptdraws * 10000; // This isn't updated until end of frame, making it useless!
10499 break;
10500
10501 case MAXDRAWS:
10502 ret = MAX_SCRIPT_DRAWING_COMMANDS * 10000;
10503 break;
10504
10505 case ISBLANKTILE: ret = (FFCore.IsBlankTile(ri->d[rINDEX]/10000) * 10000); break;
10506 case IS8BITTILE: ret = (FFCore.Is8BitTile(ri->d[rINDEX] / 10000) * 10000); break;
10507
10508 case BITMAPWIDTH:
10509 {
10510
2/4
✓ Branch 0 taken 3453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3453 times.
✗ Branch 3 not taken.
3453 if (auto bmp = user_bitmaps.check(ri->bitmapref); bmp && bmp->u_bmp)
10511 {
10512 3453 ret = bmp->width * 10000;
10513 3453 }
10514 else
10515 {
10516 ret = -10000;
10517 }
10518 3453 break;
10519 }
10520
10521 case BITMAPHEIGHT:
10522 {
10523 if (auto bmp = user_bitmaps.check(ri->bitmapref); bmp && bmp->u_bmp)
10524 {
10525 ret = bmp->height * 10000;
10526 }
10527 else
10528 {
10529 ret = -10000;
10530 }
10531 break;
10532 }
10533 ///----------------------------------------------------------------------------------------------------//
10534 //File->
10535 case FILEPOS:
10536 {
10537 if(user_file* f = checkFile(ri->fileref, true))
10538 {
10539 ret = ftell(f->file); //NOT *10000 -V
10540 }
10541 else ret = -10000L;
10542 break;
10543 }
10544 case FILEEOF:
10545 {
10546 if(user_file* f = checkFile(ri->fileref, true))
10547 {
10548 ret = feof(f->file) ? 10000L : 0L; //Boolean
10549 }
10550 else ret = -10000L;
10551 break;
10552 }
10553 case FILEERR:
10554 {
10555 if(user_file* f = checkFile(ri->fileref, true))
10556 {
10557 ret = ferror(f->file) * 10000L;
10558 }
10559 else ret = -10000L;
10560 break;
10561 }
10562
10563 ///----------------------------------------------------------------------------------------------------//
10564 //Directory->
10565 case DIRECTORYSIZE:
10566 {
10567 if(user_dir* dr = checkDir(ri->directoryref, true))
10568 {
10569 ret = dr->size() * 10000L;
10570 }
10571 else ret = -10000L;
10572 break;
10573 }
10574
10575 ///----------------------------------------------------------------------------------------------------//
10576 //Stack->
10577 case STACKSIZE:
10578 {
10579 if(user_stack* st = checkStack(ri->stackref, true))
10580 {
10581 ret = st->size(); //NOT *10000
10582 }
10583 else ret = -10000L;
10584 break;
10585 }
10586 case STACKFULL:
10587 {
10588 if(user_stack* st = checkStack(ri->stackref, true))
10589 {
10590 ret = st->full() ? 10000L : 0L;
10591 }
10592 else ret = -10000L;
10593 break;
10594 }
10595
10596 ///----------------------------------------------------------------------------------------------------//
10597 //Misc./Internal
10598 case REFFFC:
10599
2/2
✓ Branch 0 taken 730 times.
✓ Branch 1 taken 25916 times.
26646 ret = ZScriptVersion::ffcRefIsSpriteId() ? ri->ffcref : ri->ffcref * 10000;
10600 26646 break;
10601
10602 case REFITEM:
10603 608462 ret = ri->itemref;
10604 608462 break;
10605
10606 case REFITEMCLASS:
10607 5613429 ret = ri->idata;
10608 5613429 break;
10609
10610 case REFLWPN:
10611 1561191 ret = ri->lwpn;
10612 1561191 break;
10613
10614 case REFEWPN:
10615 4923553 ret = ri->ewpn;
10616 4923553 break;
10617
10618 case REFNPC:
10619 27873688 ret = ri->guyref;
10620 27873688 break;
10621
10622 case REFSPRITE:
10623 ret = ri->spriteref;
10624 break;
10625
10626 case REFMAPDATA: ret = ri->mapsref; break;
10627 case REFSCREENDATA: ret = ri->screenref; break;
10628 215684 case REFCOMBODATA: ret = ri->combosref; break;
10629 16 case REFSPRITEDATA: ret = ri->spritedataref; break;
10630 8 case REFBITMAP: ret = ri->bitmapref; break;
10631 1 case REFNPCCLASS: ret = ri->npcdataref; break;
10632
10633
10634 72917 case REFDMAPDATA: ret = ri->dmapsref; break;
10635 case REFSHOPDATA: ret = ri->shopsref; break;
10636 24 case REFMSGDATA: ret = ri->zmsgref; break;
10637 case REFUNTYPED: ret = ri->untypedref; break;
10638
10639 10 case REFDROPS: ret = ri->dropsetref; break;
10640 case REFBOTTLETYPE: ret = ri->bottletyperef; break;
10641 case REFBOTTLESHOP: ret = ri->bottleshopref; break;
10642 137691 case REFGENERICDATA: ret = ri->genericdataref; break;
10643 case REFPONDS: ret = ri->pondref; break;
10644 case REFWARPRINGS: ret = ri->warpringref; break;
10645 case REFDOORS: ret = ri->doorsref; break;
10646 case REFUICOLOURS: ret = ri->zcoloursref; break;
10647 case REFRGB: ret = ri->rgbref; break;
10648 case REFPALETTE: ret = ri->paletteref; break;
10649 case REFTUNES: ret = ri->tunesref; break;
10650 case REFPALCYCLE: ret = ri->palcycleref; break;
10651 case REFGAMEDATA: ret = ri->gamedataref; break;
10652 case REFCHEATS: ret = ri->cheatsref; break;
10653 case REFFILE: ret = ri->fileref; break;
10654 case REFDIRECTORY: ret = ri->directoryref; break;
10655 case REFSTACK: ret = ri->stackref; break;
10656 36 case REFSUBSCREEN: ret = ri->subdataref; break;
10657 case REFSUBSCREENPAGE: ret = ri->subpageref; break;
10658 case REFSUBSCREENWIDG: ret = ri->subwidgref; break;
10659 case REFRNG: ret = ri->rngref; break;
10660 case REFWEBSOCKET: ret = ri->websocketref; break;
10661 500 case CLASS_THISKEY: ret = ri->thiskey; break;
10662 120 case CLASS_THISKEY2: ret = ri->thiskey2; break;
10663 case REFPALDATA: ret = ri->paldataref; break;
10664
10665
10666 case SP:
10667 8 ret = ri->sp * 10000;
10668 8 break;
10669 case SP2:
10670 63 ret = ri->sp;
10671 63 break;
10672
10673 case PC:
10674 ret = ri->pc;
10675 break;
10676
10677 case SWITCHKEY:
10678 5 ret = ri->switchkey;
10679 5 break;
10680
10681 case SCRIPTRAM:
10682 case GLOBALRAM:
10683 1125663332 ret = ArrayH::getElement(ri->d[rINDEX] / 10000, ri->d[rINDEX2] / 10000);
10684 1125663332 break;
10685
10686 case SCRIPTRAMD:
10687 case GLOBALRAMD:
10688 ret = ArrayH::getElement(ri->d[rINDEX] / 10000, 0);
10689 break;
10690
10691 case GDD: // Unused, remove?
10692 ret = read_array(game->global_d, ri->d[rINDEX] / 10000);
10693 break;
10694
10695 ///----------------------------------------------------------------------------------------------------//
10696
10697 case PALDATACOLOR:
10698 {
10699 if (user_paldata* pd = checkPalData(ri->paldataref))
10700 {
10701 int32_t ind = ri->d[rINDEX] / 10000; // get_register(sarg1) / 10000;
10702 if (unsigned(ind) >= PALDATA_NUM_COLORS)
10703 {
10704 scripting_log_error_with_context("Invalid color index: {}. Valid indices are 0-255", ind);
10705 ret = -10000;
10706 break;
10707 }
10708
10709 if (get_bit(pd->colors_used, ind))
10710 {
10711 RGB c = pd->colors[ind];
10712
10713 ret = (c.r << 16) | (c.g << 8) | c.b;
10714 }
10715 else
10716 {
10717 //Z_scripterrlog("Color index (%d) returned an invalid color in paldata->GetColor().\n", ind);
10718 ret = -10000;
10719 break;
10720 }
10721 }
10722 break;
10723 }
10724 case PALDATAR:
10725 ret = FFCore.do_paldata_getrgb(0);
10726 break;
10727 case PALDATAG:
10728 ret = FFCore.do_paldata_getrgb(1);
10729 break;
10730 case PALDATAB:
10731 ret = FFCore.do_paldata_getrgb(2);
10732 break;
10733
10734 ///----------------------------------------------------------------------------------------------------//
10735
10736 case GENDATARUNNING:
10737 {
10738 5144 ret = 0;
10739
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5144 times.
5144 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
10740 {
10741 5144 ret = scr->doscript() ? 10000L : 0L;
10742 5144 }
10743 5144 break;
10744 }
10745 case GENDATASIZE:
10746 {
10747 ret = 0;
10748 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
10749 {
10750 ret = scr->dataSize()*10000;
10751 }
10752 break;
10753 }
10754 case GENDATAEXITSTATE:
10755 {
10756 ret = 0;
10757 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
10758 {
10759 size_t indx = ri->d[rINDEX]/10000;
10760 if(indx >= GENSCR_NUMST)
10761 {
10762 scripting_log_error_with_context("Invalid index: {}", indx);
10763 break;
10764 }
10765 ret = (scr->exitState & (1<<indx)) ? 10000L : 0;
10766 }
10767 break;
10768 }
10769 case GENDATARELOADSTATE:
10770 {
10771 ret = 0;
10772 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
10773 {
10774 size_t indx = ri->d[rINDEX]/10000;
10775 if(indx >= GENSCR_NUMST)
10776 {
10777 scripting_log_error_with_context("Invalid index: {}", indx);
10778 break;
10779 }
10780 ret = (scr->reloadState & (1<<indx)) ? 10000L : 0;
10781 }
10782 break;
10783 }
10784 case GENDATAEVENTSTATE:
10785 {
10786 ret = 0;
10787 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
10788 {
10789 size_t indx = ri->d[rINDEX]/10000;
10790 if(indx >= GENSCR_NUMEVENT)
10791 {
10792 scripting_log_error_with_context("Invalid index: {}", indx);
10793 break;
10794 }
10795 ret = (scr->eventstate & (1<<indx)) ? 10000L : 0;
10796 }
10797 break;
10798 }
10799 case GENDATADATA:
10800 {
10801 8254411 ret = 0;
10802
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8254411 times.
8254411 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
10803 {
10804 8254411 size_t indx = ri->d[rINDEX]/10000;
10805
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8254411 times.
8254411 if(indx >= scr->dataSize())
10806 {
10807 scripting_log_error_with_context("Invalid index: {}", indx);
10808 break;
10809 }
10810 8254411 ret = scr->data[indx];
10811 8254411 }
10812 8254411 break;
10813 }
10814 case GENDATAINITD:
10815 {
10816 ret = 0;
10817 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
10818 {
10819 size_t indx = ri->d[rINDEX]/10000;
10820 if(indx >= 8)
10821 {
10822 scripting_log_error_with_context("Invalid index: {}", indx);
10823 break;
10824 }
10825 ret = scr->initd[indx];
10826 }
10827 break;
10828 }
10829
10830 ///----------------------------------------------------------------------------------------------------//
10831
10832 case PORTALX:
10833 {
10834 ret = -10000;
10835 if(portal* p = checkPortal(ri->portalref))
10836 ret = p->x.getZLong();
10837 break;
10838 }
10839 case PORTALY:
10840 {
10841 ret = -10000;
10842 if(portal* p = checkPortal(ri->portalref))
10843 ret = p->y.getZLong();
10844 break;
10845 }
10846 case PORTALDMAP:
10847 {
10848 ret = -10000;
10849 if(portal* p = checkPortal(ri->portalref))
10850 ret = p->destdmap*10000;
10851 break;
10852 }
10853 case PORTALSCREEN:
10854 {
10855 ret = -10000;
10856 if(portal* p = checkPortal(ri->portalref))
10857 ret = p->destscr*10000;
10858 break;
10859 }
10860 case PORTALACLK:
10861 {
10862 ret = -10000;
10863 if(portal* p = checkPortal(ri->portalref))
10864 ret = p->aclk*10000;
10865 break;
10866 }
10867 case PORTALAFRM:
10868 {
10869 ret = -10000;
10870 if(portal* p = checkPortal(ri->portalref))
10871 ret = p->aframe*10000;
10872 break;
10873 }
10874 case PORTALOTILE:
10875 {
10876 ret = -10000;
10877 if(portal* p = checkPortal(ri->portalref))
10878 ret = p->o_tile*10000;
10879 break;
10880 }
10881 case PORTALASPD:
10882 {
10883 ret = -10000;
10884 if(portal* p = checkPortal(ri->portalref))
10885 ret = p->aspd*10000;
10886 break;
10887 }
10888 case PORTALFRAMES:
10889 {
10890 ret = -10000;
10891 if(portal* p = checkPortal(ri->portalref))
10892 ret = p->frames*10000;
10893 break;
10894 }
10895 case PORTALSAVED:
10896 {
10897 ret = 0;
10898 if(portal* p = checkPortal(ri->portalref))
10899 ret = p->saved_data;
10900 break;
10901 }
10902 case PORTALCLOSEDIS:
10903 {
10904 ret = 0;
10905 if(portal* p = checkPortal(ri->portalref))
10906 ret = p->prox_active ? 0 : 10000; //Inverted
10907 break;
10908 }
10909 case REFPORTAL:
10910 {
10911 ret = ri->portalref;
10912 break;
10913 }
10914 case REFSAVPORTAL:
10915 {
10916 ret = ri->saveportalref;
10917 break;
10918 }
10919 case PORTALWARPSFX:
10920 {
10921 ret = 0;
10922 if(portal* p = checkPortal(ri->portalref))
10923 ret = p->wsfx ? 0 : 10000;
10924 break;
10925 }
10926 case PORTALWARPVFX:
10927 {
10928 ret = 0;
10929 if(portal* p = checkPortal(ri->portalref))
10930 ret = p->weffect ? 0 : 10000;
10931 break;
10932 }
10933 case SAVEDPORTALX:
10934 {
10935 ret = -10000;
10936 if(savedportal* p = checkSavedPortal(ri->saveportalref))
10937 ret = p->x;
10938 break;
10939 }
10940 case SAVEDPORTALY:
10941 {
10942 ret = -10000;
10943 if(savedportal* p = checkSavedPortal(ri->saveportalref))
10944 ret = p->y;
10945 break;
10946 }
10947 case SAVEDPORTALSRCDMAP:
10948 {
10949 ret = -10000;
10950 if(savedportal* p = checkSavedPortal(ri->saveportalref))
10951 ret = p->srcdmap * 10000;
10952 break;
10953 }
10954 case SAVEDPORTALDESTDMAP:
10955 {
10956 ret = -10000;
10957 if(savedportal* p = checkSavedPortal(ri->saveportalref))
10958 ret = p->destdmap * 10000;
10959 break;
10960 }
10961 case SAVEDPORTALSRCSCREEN:
10962 {
10963 ret = -10000;
10964 if(savedportal* p = checkSavedPortal(ri->saveportalref))
10965 ret = p->srcscr * 10000;
10966 break;
10967 }
10968 case SAVEDPORTALDSTSCREEN:
10969 {
10970 ret = -10000;
10971 if(savedportal* p = checkSavedPortal(ri->saveportalref))
10972 ret = p->destscr * 10000;
10973 break;
10974 }
10975 case SAVEDPORTALWARPSFX:
10976 {
10977 ret = -10000;
10978 if(savedportal* p = checkSavedPortal(ri->saveportalref))
10979 ret = p->sfx * 10000;
10980 break;
10981 }
10982 case SAVEDPORTALWARPVFX:
10983 {
10984 ret = -10000;
10985 if(savedportal* p = checkSavedPortal(ri->saveportalref))
10986 ret = p->warpfx * 10000;
10987 break;
10988 }
10989 case SAVEDPORTALSPRITE:
10990 {
10991 ret = -10000;
10992 if(savedportal* p = checkSavedPortal(ri->saveportalref))
10993 ret = p->spr * 10000;
10994 break;
10995 }
10996 case SAVEDPORTALPORTAL:
10997 {
10998 ret = 0;
10999 if(savedportal* p = checkSavedPortal(ri->saveportalref))
11000 ret = getPortalFromSaved(p);
11001 break;
11002 }
11003 case PORTALCOUNT:
11004 {
11005 ret = portals.Count()*10000;
11006 break;
11007 }
11008 case SAVEDPORTALCOUNT:
11009 {
11010 ret = game->user_portals.size()*10000;
11011 break;
11012 }
11013
11014 case GAMEASUBOPEN:
11015 {
11016 ret = subscreen_open ? 10000 : 0;
11017 break;
11018 }
11019 case GAMEASUBYOFF:
11020 {
11021 14124 ret = active_sub_yoff*10000;
11022 14124 break;
11023 }
11024 case GAMENUMASUB:
11025 {
11026 ret = subscreens_active.size()*10000;
11027 break;
11028 }
11029 case GAMENUMPSUB:
11030 {
11031 ret = subscreens_passive.size()*10000;
11032 break;
11033 }
11034 case GAMENUMOSUB:
11035 {
11036 ret = subscreens_overlay.size()*10000;
11037 break;
11038 }
11039
11040 ///----------------------------------------------------------------------------------------------------//
11041
11042 case SUBDATACURPG:
11043 {
11044
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54674 times.
54674 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
11045
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54674 times.
109348 if(sub->sub_type == sstACTIVE)
11046 54674 ret = 10000*sub->curpage;
11047 54674 break;
11048 }
11049 case SUBDATANUMPG:
11050 {
11051
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
11052 {
11053
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(sub->sub_type == sstACTIVE)
11054 11 ret = 10000*sub->pages.size();
11055 else ret = 10000;
11056 11 }
11057 11 break;
11058 }
11059 case SUBDATAPAGES:
11060 {
11061
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 49958 times.
49958 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
11062 {
11063 49958 size_t indx = ri->d[rINDEX]/10000;
11064
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 49958 times.
49958 size_t sz = sub->sub_type == sstACTIVE ? sub->pages.size() : 1;
11065
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 49958 times.
49958 if(indx >= sz)
11066 {
11067 Z_scripterrlog("Bad index '%d' to array "
11068 "'subscreendata->Pages[]' of size '%d'\n", indx, sz);
11069 }
11070 else
11071 {
11072 99916 auto [sb,ty,_pg,_ind] = from_subref(ri->subdataref);
11073 99916 ret = get_subref(sb,ty,indx,0);
11074 }
11075 49958 }
11076 49958 break;
11077 }
11078 case SUBDATATYPE:
11079 {
11080 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
11081 ret = sub->sub_type*10000;
11082 break;
11083 }
11084 case SUBDATAFLAGS:
11085 {
11086 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
11087 {
11088 size_t indx = ri->d[rINDEX]/10000;
11089 size_t sz = 0;
11090 switch(sub->sub_type)
11091 {
11092 case sstACTIVE:
11093 sz = 2;
11094 break;
11095 case sstPASSIVE:
11096 sz = 0;
11097 break;
11098 case sstOVERLAY:
11099 sz = 0;
11100 break;
11101 }
11102 if(indx >= sz)
11103 {
11104 Z_scripterrlog("Bad index '%d' to array "
11105 "'subscreendata->Flags[]' of size '%d'\n", indx, sz);
11106 }
11107 else
11108 ret = (sub->flags & (1<<indx)) ? 10000 : 0;
11109 }
11110 break;
11111 }
11112 ///---- ACTIVE SUBSCREENS ONLY
11113 case SUBDATACURSORPOS:
11114 {
11115 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11116 {
11117 SubscrPage& pg = sub->cur_page();
11118 ret = pg.cursor_pos * 10000;
11119 }
11120 break;
11121 }
11122 case SUBDATASCRIPT:
11123 {
11124 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11125 ret = sub->script * 10000;
11126 break;
11127 }
11128 case SUBDATAINITD:
11129 {
11130 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11131 {
11132 size_t indx = ri->d[rINDEX]/10000;
11133 if(indx >= 8)
11134 {
11135 Z_scripterrlog("Bad index '%d' to array "
11136 "'subscreendata->InitD[8]'\n", indx);
11137 }
11138 else
11139 ret = sub->initd[indx];
11140 }
11141 break;
11142 }
11143 case SUBDATABTNLEFT:
11144 {
11145 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11146 {
11147 size_t indx = ri->d[rINDEX]/10000;
11148 if(indx >= 8)
11149 {
11150 Z_scripterrlog("Bad index '%d' to array "
11151 "'subscreendata->BtnPageLeft[8]'\n", indx);
11152 }
11153 else
11154 ret = (sub->btn_left & (1<<indx)) ? 10000 : 0;
11155 }
11156 break;
11157 }
11158 case SUBDATABTNRIGHT:
11159 {
11160 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11161 {
11162 size_t indx = ri->d[rINDEX]/10000;
11163 if(indx >= 8)
11164 {
11165 Z_scripterrlog("Bad index '%d' to array "
11166 "'subscreendata->BtnPageRight[8]'\n", indx);
11167 }
11168 else
11169 ret = (sub->btn_right & (1<<indx)) ? 10000 : 0;
11170 }
11171 break;
11172 }
11173 case SUBDATATRANSLEFTTY:
11174 {
11175 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11176 {
11177 auto& trans = sub->trans_left;
11178 ret = trans.type * 10000;
11179 }
11180 break;
11181 }
11182 case SUBDATATRANSLEFTSFX:
11183 {
11184 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11185 {
11186 auto& trans = sub->trans_left;
11187 ret = trans.tr_sfx * 10000;
11188 }
11189 break;
11190 }
11191 case SUBDATATRANSLEFTFLAGS:
11192 {
11193 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11194 {
11195 auto& trans = sub->trans_left;
11196 size_t indx = ri->d[rINDEX]/10000;
11197 if(indx >= SUBSCR_TRANS_NUMFLAGS)
11198 {
11199 Z_scripterrlog("Bad index '%d' to array "
11200 "'subscreendata->TransLeftFlags[%d]'\n", indx, SUBSCR_TRANS_NUMFLAGS);
11201 }
11202 else
11203 ret = (trans.flags & (1<<indx)) ? 10000 : 0;
11204 }
11205 break;
11206 }
11207 case SUBDATATRANSLEFTARGS:
11208 {
11209 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11210 {
11211 auto& trans = sub->trans_left;
11212 size_t indx = ri->d[rINDEX]/10000;
11213 if(indx >= SUBSCR_TRANSITION_MAXARG)
11214 {
11215 Z_scripterrlog("Bad index '%d' to array "
11216 "'subscreendata->TransLeftArgs[%d]'\n", indx, SUBSCR_TRANSITION_MAXARG);
11217 }
11218 else
11219 ret = trans.arg[indx]*SubscrTransition::argScale(trans.type,indx);
11220 }
11221 break;
11222 }
11223 case SUBDATATRANSRIGHTTY:
11224 {
11225 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11226 {
11227 auto& trans = sub->trans_right;
11228 ret = trans.type * 10000;
11229 }
11230 break;
11231 }
11232 case SUBDATATRANSRIGHTSFX:
11233 {
11234 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11235 {
11236 auto& trans = sub->trans_right;
11237 ret = trans.tr_sfx * 10000;
11238 }
11239 break;
11240 }
11241 case SUBDATATRANSRIGHTFLAGS:
11242 {
11243 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11244 {
11245 auto& trans = sub->trans_right;
11246 size_t indx = ri->d[rINDEX]/10000;
11247 if(indx >= SUBSCR_TRANS_NUMFLAGS)
11248 {
11249 Z_scripterrlog("Bad index '%d' to array "
11250 "'subscreendata->TransRightFlags[%d]'\n", indx, SUBSCR_TRANS_NUMFLAGS);
11251 }
11252 else
11253 ret = (trans.flags & (1<<indx)) ? 10000 : 0;
11254 }
11255 break;
11256 }
11257 case SUBDATATRANSRIGHTARGS:
11258 {
11259 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11260 {
11261 auto& trans = sub->trans_right;
11262 size_t indx = ri->d[rINDEX]/10000;
11263 if(indx >= SUBSCR_TRANSITION_MAXARG)
11264 {
11265 Z_scripterrlog("Bad index '%d' to array "
11266 "'subscreendata->TransRightArgs[%d]'\n", indx, SUBSCR_TRANSITION_MAXARG);
11267 }
11268 else
11269 ret = trans.arg[indx]*SubscrTransition::argScale(trans.type,indx);
11270 }
11271 break;
11272 }
11273 case SUBDATASELECTORDSTX:
11274 {
11275 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11276 ret = sub->selector_setting.x * 10000;
11277 break;
11278 }
11279 case SUBDATASELECTORDSTY:
11280 {
11281 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11282 ret = sub->selector_setting.y * 10000;
11283 break;
11284 }
11285 case SUBDATASELECTORDSTW:
11286 {
11287 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11288 ret = sub->selector_setting.w * 10000;
11289 break;
11290 }
11291 case SUBDATASELECTORDSTH:
11292 {
11293 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11294 ret = sub->selector_setting.h * 10000;
11295 break;
11296 }
11297 case SUBDATASELECTORWID:
11298 {
11299 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11300 {
11301 size_t indx = ri->d[rINDEX]/10000;
11302 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
11303 {
11304 Z_scripterrlog("Bad index '%d' to array 'subscreendata->"
11305 "SelectorDestWid[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
11306 }
11307 else
11308 ret = sub->selector_setting.tileinfo[indx].sw * 10000;
11309 }
11310 break;
11311 }
11312 case SUBDATASELECTORHEI:
11313 {
11314 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11315 {
11316 size_t indx = ri->d[rINDEX]/10000;
11317 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
11318 {
11319 Z_scripterrlog("Bad index '%d' to array 'subscreendata->"
11320 "SelectorDestHei[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
11321 }
11322 else
11323 ret = sub->selector_setting.tileinfo[indx].sh * 10000;
11324 }
11325 break;
11326 }
11327 case SUBDATASELECTORTILE:
11328 {
11329 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11330 {
11331 size_t indx = ri->d[rINDEX]/10000;
11332 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
11333 {
11334 Z_scripterrlog("Bad index '%d' to array 'subscreendata->"
11335 "SelectorTile[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
11336 }
11337 else
11338 ret = sub->selector_setting.tileinfo[indx].tile * 10000;
11339 }
11340 break;
11341 }
11342 case SUBDATASELECTORCSET:
11343 {
11344 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11345 {
11346 size_t indx = ri->d[rINDEX]/10000;
11347 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
11348 {
11349 Z_scripterrlog("Bad index '%d' to array 'subscreendata->"
11350 "SelectorCSet[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
11351 }
11352 else
11353 {
11354 byte& cs = sub->selector_setting.tileinfo[indx].cset;
11355 ret = (cs&0x0F) * 10000;
11356 }
11357 }
11358 break;
11359 }
11360 case SUBDATASELECTORFLASHCSET:
11361 {
11362 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11363 {
11364 size_t indx = ri->d[rINDEX]/10000;
11365 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
11366 {
11367 Z_scripterrlog("Bad index '%d' to array 'subscreendata->"
11368 "SelectorFlashCSet[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
11369 }
11370 else
11371 {
11372 byte& cs = sub->selector_setting.tileinfo[indx].cset;
11373 ret = ((cs&0xF0)>>4) * 10000;
11374 }
11375 }
11376 break;
11377 }
11378 case SUBDATASELECTORFRM:
11379 {
11380 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11381 {
11382 size_t indx = ri->d[rINDEX]/10000;
11383 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
11384 {
11385 Z_scripterrlog("Bad index '%d' to array 'subscreendata->"
11386 "SelectorFrames[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
11387 }
11388 else
11389 ret = sub->selector_setting.tileinfo[indx].frames * 10000;
11390 }
11391 break;
11392 }
11393 case SUBDATASELECTORASPD:
11394 {
11395 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11396 {
11397 size_t indx = ri->d[rINDEX]/10000;
11398 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
11399 {
11400 Z_scripterrlog("Bad index '%d' to array 'subscreendata->"
11401 "SelectorASpeed[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
11402 }
11403 else
11404 ret = sub->selector_setting.tileinfo[indx].speed * 10000;
11405 }
11406 break;
11407 }
11408 case SUBDATASELECTORDELAY:
11409 {
11410 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11411 {
11412 size_t indx = ri->d[rINDEX]/10000;
11413 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
11414 {
11415 Z_scripterrlog("Bad index '%d' to array 'subscreendata->"
11416 "SelectorDelay[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
11417 }
11418 else
11419 ret = sub->selector_setting.tileinfo[indx].delay * 10000;
11420 }
11421 break;
11422 }
11423 ///---- CURRENTLY OPEN ACTIVE SUBSCREEN ONLY
11424 case SUBDATATRANSCLK:
11425 {
11426 5031 ret = -10000;
11427
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5031 times.
5031 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11428 {
11429
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5031 times.
5031 if(sub != new_subscreen_active)
11430 Z_scripterrlog("'subscreendata->TransClock' is only"
11431 " valid for the current active subscreen!\n");
11432
3/4
✓ Branch 0 taken 5031 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4855 times.
✓ Branch 3 taken 176 times.
5031 else if(subscreen_open && subscr_pg_animating)
11433 176 ret = subscr_pg_clk*10000;
11434 5031 }
11435 5031 break;
11436 }
11437 case SUBDATATRANSTY:
11438 {
11439 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11440 {
11441 auto& trans = subscr_pg_transition;
11442 if(sub != new_subscreen_active)
11443 Z_scripterrlog("'subscreendata->TransType' is only"
11444 " valid for the current active subscreen!\n");
11445 else if(subscreen_open)
11446 ret = trans.type*10000;
11447 }
11448 break;
11449 }
11450 case SUBDATATRANSFLAGS:
11451 {
11452 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11453 {
11454 auto& trans = subscr_pg_transition;
11455 size_t indx = ri->d[rINDEX]/10000;
11456 if(indx >= SUBSCR_TRANS_NUMFLAGS)
11457 {
11458 Z_scripterrlog("Bad index '%d' to array "
11459 "'subscreendata->TransFlags[%d]'\n", indx, SUBSCR_TRANS_NUMFLAGS);
11460 }
11461 else if(sub != new_subscreen_active)
11462 Z_scripterrlog("'subscreendata->TransType' is only"
11463 " valid for the current active subscreen!\n");
11464 else if(subscreen_open)
11465 ret = (trans.flags & (1<<indx)) ? 10000 : 0;
11466 }
11467 break;
11468 }
11469 case SUBDATATRANSARGS:
11470 {
11471 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11472 {
11473 auto& trans = subscr_pg_transition;
11474 size_t indx = ri->d[rINDEX]/10000;
11475 if(indx >= SUBSCR_TRANSITION_MAXARG)
11476 {
11477 Z_scripterrlog("Bad index '%d' to array "
11478 "'subscreendata->TransArgs[%d]'\n", indx, SUBSCR_TRANSITION_MAXARG);
11479 }
11480 else if(sub != new_subscreen_active)
11481 Z_scripterrlog("'subscreendata->TransType' is only"
11482 " valid for the current active subscreen!\n");
11483 else if(subscreen_open)
11484 ret = trans.arg[indx]*SubscrTransition::argScale(trans.type,indx);
11485 }
11486 break;
11487 }
11488 case SUBDATATRANSFROMPG:
11489 {
11490 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11491 {
11492 if(sub != new_subscreen_active)
11493 Z_scripterrlog("'subscreendata->TransFromPage' is only"
11494 " valid for the current active subscreen!\n");
11495 else if(subscreen_open)
11496 ret = subscr_pg_from*10000;
11497 }
11498 break;
11499 }
11500 case SUBDATATRANSTOPG:
11501 {
11502 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
11503 {
11504 if(sub != new_subscreen_active)
11505 Z_scripterrlog("'subscreendata->TransToPage' is only"
11506 " valid for the current active subscreen!\n");
11507 else if(subscreen_open)
11508 ret = subscr_pg_to*10000;
11509 }
11510 break;
11511 }
11512
11513 ///----------------------------------------------------------------------------------------------------//
11514 case SUBPGINDEX:
11515 {
11516 if(SubscrPage* pg = checkSubPage(ri->subpageref))
11517 ret = pg->getIndex() * 10000;
11518 break;
11519 }
11520 case SUBPGNUMWIDG:
11521 {
11522
1/2
✓ Branch 0 taken 1005 times.
✗ Branch 1 not taken.
1005 if(SubscrPage* pg = checkSubPage(ri->subpageref))
11523 1005 ret = pg->size() * 10000;
11524 1005 break;
11525 }
11526 case SUBPGWIDGETS:
11527 {
11528
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2475 times.
2475 if(SubscrPage* pg = checkSubPage(ri->subpageref))
11529 {
11530 2475 size_t indx = ri->d[rINDEX]/10000;
11531 2475 size_t sz = pg->size();
11532
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2475 times.
2475 if(indx >= sz)
11533 {
11534 scripting_log_error_with_context("Bad index '{}' for array of size '{}'", indx, sz);
11535 }
11536 else
11537 {
11538 7425 auto [sb,ty,pg,_ind] = from_subref(ri->subpageref);
11539 7425 ret = get_subref(sb,ty,pg,indx);
11540 }
11541 2475 }
11542 2475 break;
11543 }
11544 case SUBPGSUBDATA:
11545 {
11546 if(SubscrPage* pg = checkSubPage(ri->subpageref))
11547 {
11548 auto [sub,ty,_pgid,_ind] = from_subref(ri->subpageref);
11549 ret = get_subref(sub,ty,0,0);
11550 }
11551 break;
11552 }
11553 case SUBPGCURSORPOS:
11554 {
11555
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17326 times.
17326 if(SubscrPage* pg = checkSubPage(ri->subpageref))
11556 17326 ret = pg->cursor_pos * 10000;
11557 17326 break;
11558 }
11559 ///----------------------------------------------------------------------------------------------------//
11560 ///---- ANY WIDGET TYPE
11561 case SUBWIDGTYPE:
11562 {
11563
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6024 times.
6024 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11564 6024 ret = 10000*widg->getType();
11565 6024 break;
11566 }
11567 case SUBWIDGINDEX:
11568 {
11569 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11570 {
11571 auto [_sub,_ty,_pgid,ind] = from_subref(ri->subwidgref);
11572 ret = 10000*ind;
11573 }
11574 break;
11575 }
11576 case SUBWIDGDISPITM:
11577 {
11578
1/2
✓ Branch 0 taken 4206 times.
✗ Branch 1 not taken.
4206 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11579 {
11580 4206 ret = 10000*widg->getDisplayItem();
11581 4206 }
11582 4206 break;
11583 }
11584 case SUBWIDGEQPITM:
11585 {
11586
1/2
✓ Branch 0 taken 9836 times.
✗ Branch 1 not taken.
9836 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11587 {
11588 9836 ret = 10000*widg->getItemVal();
11589 9836 }
11590 9836 break;
11591 }
11592 case SUBWIDGPAGE:
11593 {
11594 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11595 {
11596 auto [sub,ty,pgid,_ind] = from_subref(ri->subwidgref);
11597 ret = get_subref(sub,ty,pgid,0);
11598 }
11599 break;
11600 }
11601 case SUBWIDGPOS:
11602 {
11603 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11604 ret = 10000*widg->pos;
11605 break;
11606 }
11607 case SUBWIDGPOSES:
11608 {
11609 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11610 {
11611 size_t indx = ri->d[rINDEX]/10000;
11612 if(indx >= 4)
11613 {
11614 Z_scripterrlog("Bad index '%d' to array "
11615 "'subscreenwidget->PosDirs[%d]'\n", indx, 4);
11616 ret = -10000;
11617 }
11618 else
11619 {
11620 switch(indx)
11621 {
11622 case up:
11623 ret = 10000*widg->pos_up;
11624 break;
11625 case down:
11626 ret = 10000*widg->pos_down;
11627 break;
11628 case left:
11629 ret = 10000*widg->pos_left;
11630 break;
11631 case right:
11632 ret = 10000*widg->pos_right;
11633 break;
11634 }
11635 }
11636 }
11637 break;
11638 }
11639 case SUBWIDGPOSFLAG:
11640 {
11641 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11642 {
11643 size_t indx = ri->d[rINDEX]/10000;
11644 if(indx >= sspNUM)
11645 {
11646 Z_scripterrlog("Bad index '%d' to array "
11647 "'subscreenwidget->VisibleFlags[%d]'\n", indx, sspNUM);
11648 }
11649 else ret = (widg->posflags & (1<<indx)) ? 10000 : 0;
11650 }
11651 break;
11652 }
11653 case SUBWIDGX:
11654 {
11655
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 339 times.
339 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11656 339 ret = 10000*widg->x;
11657 339 break;
11658 }
11659 case SUBWIDGY:
11660 {
11661
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 339 times.
339 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11662 339 ret = 10000*widg->y;
11663 339 break;
11664 }
11665 case SUBWIDGW:
11666 {
11667 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11668 ret = 10000*widg->w;
11669 break;
11670 }
11671 case SUBWIDGH:
11672 {
11673 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11674 ret = 10000*widg->h;
11675 break;
11676 }
11677 case SUBWIDG_DISPX:
11678 {
11679 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11680 ret = 10000*widg->getX();
11681 break;
11682 }
11683 case SUBWIDG_DISPY:
11684 {
11685 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11686 ret = 10000*widg->getY();
11687 break;
11688 }
11689 case SUBWIDG_DISPW:
11690 {
11691 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11692 ret = 10000*widg->getW();
11693 break;
11694 }
11695 case SUBWIDG_DISPH:
11696 {
11697 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11698 ret = 10000*widg->getH();
11699 break;
11700 }
11701 case SUBWIDGGENFLAG:
11702 {
11703 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11704 {
11705 size_t indx = ri->d[rINDEX]/10000;
11706 if(indx >= SUBSCRFLAG_GEN_COUNT)
11707 {
11708 Z_scripterrlog("Bad index '%d' to array "
11709 "'subscreenwidget->GenFlags[%d]'\n", indx, SUBSCRFLAG_GEN_COUNT);
11710 }
11711 else ret = (widg->genflags & (1<<indx)) ? 10000 : 0;
11712 }
11713 break;
11714 }
11715 case SUBWIDGFLAG:
11716 {
11717 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11718 {
11719 size_t indx = ri->d[rINDEX]/10000;
11720 byte sz = widg->numFlags();
11721 if (BC::checkIndex2(indx, sz) == SH::_NoError)
11722 ret = (widg->flags & (1<<indx)) ? 10000 : 0;
11723 }
11724 break;
11725 }
11726 case SUBWIDGREQOWNITEMS:
11727 {
11728 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11729 {
11730 size_t indx = ri->d[rINDEX]/10000;
11731 if (BC::checkIndex2(indx, MAXITEMS) == SH::_NoError)
11732 ret = widg->req_owned_items.contains(indx) ? 10000 : 0;
11733 }
11734 break;
11735 }
11736 case SUBWIDGREQUNOWNITEMS:
11737 {
11738 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11739 {
11740 size_t indx = ri->d[rINDEX]/10000;
11741 if (BC::checkIndex2(indx, MAXITEMS) == SH::_NoError)
11742 ret = widg->req_unowned_items.contains(indx) ? 10000 : 0;
11743 }
11744 break;
11745 }
11746 case SUBWIDGREQCOUNTER:
11747 {
11748 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11749 ret = 10000 * widg->req_counter;
11750 break;
11751 }
11752 case SUBWIDGREQCOUNTERCOND:
11753 {
11754 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11755 ret = 10000 * widg->req_counter_cond_type;
11756 break;
11757 }
11758 case SUBWIDGREQCOUNTERVAL:
11759 {
11760 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11761 ret = 10000 * widg->req_counter_val;
11762 break;
11763 }
11764 case SUBWIDGREQLITEMS:
11765 {
11766 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11767 ret = 10000 * widg->req_litems;
11768 break;
11769 }
11770 case SUBWIDGREQLITEMLEVEL:
11771 {
11772 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11773 ret = 10000 * widg->req_litem_level;
11774 break;
11775 }
11776 case SUBWIDGREQSCRIPTDISABLED:
11777 {
11778 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
11779 ret = widg->is_disabled ? 10000 : 0;
11780 break;
11781 }
11782 ///---- ACTIVE SUBSCREENS ONLY
11783 case SUBWIDGSELECTORDSTX:
11784 {
11785 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11786 ret = 10000*widg->selector_override.x;
11787 break;
11788 }
11789 case SUBWIDGSELECTORDSTY:
11790 {
11791 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11792 ret = 10000*widg->selector_override.y;
11793 break;
11794 }
11795 case SUBWIDGSELECTORDSTW:
11796 {
11797 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11798 ret = 10000*widg->selector_override.w;
11799 break;
11800 }
11801 case SUBWIDGSELECTORDSTH:
11802 {
11803 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11804 ret = 10000*widg->selector_override.h;
11805 break;
11806 }
11807 case SUBWIDGSELECTORWID:
11808 {
11809 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11810 {
11811 size_t indx = ri->d[rINDEX]/10000;
11812 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
11813 {
11814 Z_scripterrlog("Bad index '%d' to array 'subscreenwidget->"
11815 "SelectorDestWid[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
11816 }
11817 else ret = 10000*widg->selector_override.tileinfo[indx].sw;
11818 }
11819 break;
11820 }
11821 case SUBWIDGSELECTORHEI:
11822 {
11823 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11824 {
11825 size_t indx = ri->d[rINDEX]/10000;
11826 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
11827 {
11828 Z_scripterrlog("Bad index '%d' to array 'subscreenwidget->"
11829 "SelectorDestHei[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
11830 }
11831 else ret = 10000*widg->selector_override.tileinfo[indx].sh;
11832 }
11833 break;
11834 }
11835 case SUBWIDGSELECTORTILE:
11836 {
11837 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11838 {
11839 size_t indx = ri->d[rINDEX]/10000;
11840 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
11841 {
11842 Z_scripterrlog("Bad index '%d' to array 'subscreenwidget->"
11843 "SelectorTile[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
11844 }
11845 else ret = 10000*widg->selector_override.tileinfo[indx].tile;
11846 }
11847 break;
11848 }
11849 case SUBWIDGSELECTORCSET:
11850 {
11851 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11852 {
11853 size_t indx = ri->d[rINDEX]/10000;
11854 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
11855 {
11856 Z_scripterrlog("Bad index '%d' to array 'subscreenwidget->"
11857 "SelectorCSet[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
11858 }
11859 else ret = 10000*(widg->selector_override.tileinfo[indx].cset&0xF);
11860 }
11861 break;
11862 }
11863 case SUBWIDGSELECTORFLASHCSET:
11864 {
11865 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11866 {
11867 size_t indx = ri->d[rINDEX]/10000;
11868 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
11869 {
11870 Z_scripterrlog("Bad index '%d' to array 'subscreenwidget->"
11871 "SelectorFlashCSet[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
11872 }
11873 else ret = 10000*((widg->selector_override.tileinfo[indx].cset&0xF0)>>4);
11874 }
11875 break;
11876 }
11877 case SUBWIDGSELECTORFRM:
11878 {
11879 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11880 {
11881 size_t indx = ri->d[rINDEX]/10000;
11882 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
11883 {
11884 Z_scripterrlog("Bad index '%d' to array 'subscreenwidget->"
11885 "SelectorFrames[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
11886 }
11887 else ret = 10000*widg->selector_override.tileinfo[indx].frames;
11888 }
11889 break;
11890 }
11891 case SUBWIDGSELECTORASPD:
11892 {
11893 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11894 {
11895 size_t indx = ri->d[rINDEX]/10000;
11896 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
11897 {
11898 Z_scripterrlog("Bad index '%d' to array 'subscreenwidget->"
11899 "SelectorASpeed[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
11900 }
11901 else ret = 10000*widg->selector_override.tileinfo[indx].speed;
11902 }
11903 break;
11904 }
11905 case SUBWIDGSELECTORDELAY:
11906 {
11907 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11908 {
11909 size_t indx = ri->d[rINDEX]/10000;
11910 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
11911 {
11912 Z_scripterrlog("Bad index '%d' to array 'subscreenwidget->"
11913 "SelectorDelay[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
11914 }
11915 else ret = 10000*widg->selector_override.tileinfo[indx].delay;
11916 }
11917 break;
11918 }
11919
11920 case SUBWIDGPRESSSCRIPT:
11921 {
11922 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11923 ret = 10000*widg->generic_script;
11924 break;
11925 }
11926 case SUBWIDGPRESSINITD:
11927 {
11928 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11929 {
11930 size_t indx = ri->d[rINDEX]/10000;
11931 if(indx >= 8)
11932 {
11933 Z_scripterrlog("Bad index '%d' to array "
11934 "'subscreenwidget->PressInitD[8]'\n", indx);
11935 }
11936 else ret = widg->generic_initd[indx];
11937 }
11938 break;
11939 }
11940 case SUBWIDGBTNPRESS:
11941 {
11942 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11943 {
11944 size_t indx = ri->d[rINDEX]/10000;
11945 if(indx >= 8)
11946 {
11947 Z_scripterrlog("Bad index '%d' to array "
11948 "'subscreenwidget->BtnPressScript[8]'\n", indx);
11949 }
11950 else ret = (widg->gen_script_btns & (1<<indx)) ? 10000 : 0;
11951 }
11952 break;
11953 }
11954 case SUBWIDGBTNPG:
11955 {
11956 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11957 {
11958 size_t indx = ri->d[rINDEX]/10000;
11959 if(indx >= 8)
11960 {
11961 Z_scripterrlog("Bad index '%d' to array "
11962 "'subscreenwidget->BtnPageChange[8]'\n", indx);
11963 }
11964 else ret = (widg->pg_btns & (1<<indx)) ? 10000 : 0;
11965 }
11966 break;
11967 }
11968 case SUBWIDGPGMODE:
11969 {
11970 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11971 ret = 10000*widg->pg_mode;
11972 break;
11973 }
11974 case SUBWIDGPGTARG:
11975 {
11976 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11977 ret = 10000*widg->pg_targ;
11978 break;
11979 }
11980
11981 case SUBWIDGTRANSPGTY:
11982 {
11983 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11984 {
11985 auto& trans = widg->pg_trans;
11986 ret = 10000*trans.type;
11987 }
11988 break;
11989 }
11990 case SUBWIDGTRANSPGSFX:
11991 {
11992 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
11993 {
11994 auto& trans = widg->pg_trans;
11995 ret = 10000*trans.tr_sfx;
11996 }
11997 break;
11998 }
11999 case SUBWIDGTRANSPGFLAGS:
12000 {
12001 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
12002 {
12003 auto& trans = widg->pg_trans;
12004 size_t indx = ri->d[rINDEX]/10000;
12005 if(indx >= SUBSCR_TRANS_NUMFLAGS)
12006 {
12007 Z_scripterrlog("Bad index '%d' to array "
12008 "'subscreenwidget->PageTransFlags[%d]'\n", indx, SUBSCR_TRANS_NUMFLAGS);
12009 }
12010 else ret = (trans.flags & (1<<indx)) ? 10000 : 0;
12011 }
12012 break;
12013 }
12014 case SUBWIDGTRANSPGARGS:
12015 {
12016 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
12017 {
12018 auto& trans = widg->pg_trans;
12019 size_t indx = ri->d[rINDEX]/10000;
12020 if(indx >= SUBSCR_TRANSITION_MAXARG)
12021 {
12022 Z_scripterrlog("Bad index '%d' to array "
12023 "'subscreenwidget->PageTransArgs[%d]'\n", indx, SUBSCR_TRANSITION_MAXARG);
12024 }
12025 else ret = trans.arg[indx]*SubscrTransition::argScale(trans.type,indx);
12026 }
12027 break;
12028 }
12029 ///---- VARYING WIDGET TYPES
12030 case SUBWIDGTY_CSET:
12031 {
12032 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12033 {
12034 size_t indx = ri->d[rINDEX]/10000;
12035 size_t sz = 0;
12036 byte ty = widg->getType();
12037 switch(ty)
12038 {
12039 case widgFRAME:
12040 case widgMCGUFF:
12041 case widgTILEBLOCK:
12042 case widgMINITILE:
12043 sz = 1;
12044 break;
12045 case widgLGAUGE:
12046 case widgMGAUGE:
12047 case widgMISCGAUGE:
12048 sz = 4;
12049 break;
12050 default:
12051 sz = 0;
12052 bad_subwidg_type(false, ty);
12053 ret = -10000;
12054 break;
12055 }
12056 if(!sz) break;
12057 if(indx >= sz)
12058 {
12059 Z_scripterrlog("Bad index '%d' to array "
12060 "'subscreenwidget->CSet[%d]'\n", indx, sz);
12061 break;
12062 }
12063 switch(ty)
12064 {
12065 case widgFRAME:
12066 ret = ((SW_2x2Frame*)widg)->cs.get_cset()*10000;
12067 break;
12068 case widgMCGUFF:
12069 ret = ((SW_McGuffin*)widg)->cs.get_cset()*10000;
12070 break;
12071 case widgTILEBLOCK:
12072 ret = ((SW_TileBlock*)widg)->cs.get_cset()*10000;
12073 break;
12074 case widgMINITILE:
12075 ret = ((SW_MiniTile*)widg)->cs.get_cset()*10000;
12076 break;
12077 case widgLGAUGE:
12078 case widgMGAUGE:
12079 case widgMISCGAUGE:
12080 ret = 10000*((SW_GaugePiece*)widg)->mts[indx].cset;
12081 break;
12082 }
12083 }
12084 break;
12085 }
12086 case SUBWIDGTY_TILE:
12087 {
12088 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12089 {
12090 size_t indx = ri->d[rINDEX]/10000;
12091 size_t sz = 0;
12092 byte ty = widg->getType();
12093 switch(ty)
12094 {
12095 case widgFRAME:
12096 case widgMCGUFF:
12097 case widgTILEBLOCK:
12098 case widgMINITILE:
12099 sz = 1;
12100 break;
12101 case widgLGAUGE:
12102 case widgMGAUGE:
12103 case widgMISCGAUGE:
12104 sz = 4;
12105 break;
12106 default:
12107 sz = 0;
12108 bad_subwidg_type(false, ty);
12109 ret = -10000;
12110 break;
12111 }
12112 if(!sz) break;
12113 if(indx >= sz)
12114 {
12115 Z_scripterrlog("Bad index '%d' to array "
12116 "'subscreenwidget->Tile[%d]'\n", indx, sz);
12117 break;
12118 }
12119 switch(ty)
12120 {
12121 case widgFRAME:
12122 ret = ret = 10000*((SW_2x2Frame*)widg)->tile;
12123 break;
12124 case widgMCGUFF:
12125 ret = 10000*((SW_McGuffin*)widg)->tile;
12126 break;
12127 case widgTILEBLOCK:
12128 ret = 10000*((SW_TileBlock*)widg)->tile;
12129 break;
12130 case widgMINITILE:
12131 ret = 10000*((SW_MiniTile*)widg)->get_int_tile();
12132 break;
12133 case widgLGAUGE:
12134 case widgMGAUGE:
12135 case widgMISCGAUGE:
12136 ret = 10000*((SW_GaugePiece*)widg)->mts[indx].tile();
12137 break;
12138 }
12139 }
12140 break;
12141 }
12142 case SUBWIDGTY_FONT:
12143 {
12144 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12145 {
12146 auto ty = widg->getType();
12147 switch(ty)
12148 {
12149 case widgTEXT:
12150 ret = 10000*((SW_Text*)widg)->fontid;
12151 break;
12152 case widgTEXTBOX:
12153 ret = 10000*((SW_TextBox*)widg)->fontid;
12154 break;
12155 case widgSELECTEDTEXT:
12156 ret = 10000*((SW_SelectedText*)widg)->fontid;
12157 break;
12158 case widgTIME:
12159 ret = 10000*((SW_Time*)widg)->fontid;
12160 break;
12161 case widgCOUNTER:
12162 ret = 10000*((SW_Counter*)widg)->fontid;
12163 break;
12164 case widgBTNCOUNTER:
12165 ret = 10000*((SW_BtnCounter*)widg)->fontid;
12166 break;
12167 case widgOLDCTR:
12168 ret = 10000*((SW_Counters*)widg)->fontid;
12169 break;
12170 case widgMMAPTITLE:
12171 ret = 10000*((SW_MMapTitle*)widg)->fontid;
12172 break;
12173 default:
12174 bad_subwidg_type(false, ty);
12175 ret = -10000;
12176 break;
12177 }
12178 }
12179 break;
12180 }
12181 case SUBWIDGTY_ALIGN:
12182 {
12183 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12184 {
12185 auto ty = widg->getType();
12186 switch(ty)
12187 {
12188 case widgTEXT:
12189 ret = 10000*((SW_Text*)widg)->align;
12190 break;
12191 case widgTEXTBOX:
12192 ret = 10000*((SW_TextBox*)widg)->align;
12193 break;
12194 case widgSELECTEDTEXT:
12195 ret = 10000*((SW_SelectedText*)widg)->align;
12196 break;
12197 case widgTIME:
12198 ret = 10000*((SW_Time*)widg)->align;
12199 break;
12200 case widgCOUNTER:
12201 ret = 10000*((SW_Counter*)widg)->align;
12202 break;
12203 case widgBTNCOUNTER:
12204 ret = 10000*((SW_BtnCounter*)widg)->align;
12205 break;
12206 case widgMMAPTITLE:
12207 ret = 10000*((SW_MMapTitle*)widg)->align;
12208 break;
12209 default:
12210 bad_subwidg_type(false, ty);
12211 ret = -10000;
12212 break;
12213 }
12214 }
12215 break;
12216 }
12217 case SUBWIDGTY_SHADOWTY:
12218 {
12219 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12220 {
12221 auto ty = widg->getType();
12222 switch(ty)
12223 {
12224 case widgTEXT:
12225 ret = 10000*((SW_Text*)widg)->shadtype;
12226 break;
12227 case widgTEXTBOX:
12228 ret = 10000*((SW_TextBox*)widg)->shadtype;
12229 break;
12230 case widgSELECTEDTEXT:
12231 ret = 10000*((SW_SelectedText*)widg)->shadtype;
12232 break;
12233 case widgTIME:
12234 ret = 10000*((SW_Time*)widg)->shadtype;
12235 break;
12236 case widgCOUNTER:
12237 ret = 10000*((SW_Counter*)widg)->shadtype;
12238 break;
12239 case widgBTNCOUNTER:
12240 ret = 10000*((SW_BtnCounter*)widg)->shadtype;
12241 break;
12242 case widgOLDCTR:
12243 ret = 10000*((SW_Counters*)widg)->shadtype;
12244 break;
12245 case widgMMAPTITLE:
12246 ret = 10000*((SW_MMapTitle*)widg)->shadtype;
12247 break;
12248 default:
12249 bad_subwidg_type(false, ty);
12250 ret = -10000;
12251 break;
12252 }
12253 }
12254 break;
12255 }
12256 case SUBWIDGTY_COLOR_TXT:
12257 {
12258 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12259 {
12260 auto ty = widg->getType();
12261 switch(ty)
12262 {
12263 case widgTEXT:
12264 ret = 10000*((SW_Text*)widg)->c_text.get_int_color();
12265 break;
12266 case widgTEXTBOX:
12267 ret = 10000*((SW_TextBox*)widg)->c_text.get_int_color();
12268 break;
12269 case widgSELECTEDTEXT:
12270 ret = 10000*((SW_SelectedText*)widg)->c_text.get_int_color();
12271 break;
12272 case widgTIME:
12273 ret = 10000*((SW_Time*)widg)->c_text.get_int_color();
12274 break;
12275 case widgCOUNTER:
12276 ret = 10000*((SW_Counter*)widg)->c_text.get_int_color();
12277 break;
12278 case widgBTNCOUNTER:
12279 ret = 10000*((SW_BtnCounter*)widg)->c_text.get_int_color();
12280 break;
12281 case widgOLDCTR:
12282 ret = 10000*((SW_Counters*)widg)->c_text.get_int_color();
12283 break;
12284 case widgMMAPTITLE:
12285 ret = 10000*((SW_MMapTitle*)widg)->c_text.get_int_color();
12286 break;
12287 case widgMCGUFF_FRAME:
12288 ret = 10000*((SW_TriFrame*)widg)->c_number.get_int_color();
12289 break;
12290 default:
12291 bad_subwidg_type(false, ty);
12292 break;
12293 }
12294 }
12295 break;
12296 }
12297 case SUBWIDGTY_COLOR_SHD:
12298 {
12299 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12300 {
12301 auto ty = widg->getType();
12302 switch(ty)
12303 {
12304 case widgTEXT:
12305 ret = 10000*((SW_Text*)widg)->c_shadow.get_int_color();
12306 break;
12307 case widgTEXTBOX:
12308 ret = 10000*((SW_TextBox*)widg)->c_shadow.get_int_color();
12309 break;
12310 case widgSELECTEDTEXT:
12311 ret = 10000*((SW_SelectedText*)widg)->c_shadow.get_int_color();
12312 break;
12313 case widgTIME:
12314 ret = 10000*((SW_Time*)widg)->c_shadow.get_int_color();
12315 break;
12316 case widgCOUNTER:
12317 ret = 10000*((SW_Counter*)widg)->c_shadow.get_int_color();
12318 break;
12319 case widgBTNCOUNTER:
12320 ret = 10000*((SW_BtnCounter*)widg)->c_shadow.get_int_color();
12321 break;
12322 case widgOLDCTR:
12323 ret = 10000*((SW_Counters*)widg)->c_shadow.get_int_color();
12324 break;
12325 case widgMMAPTITLE:
12326 ret = 10000*((SW_MMapTitle*)widg)->c_shadow.get_int_color();
12327 break;
12328 default:
12329 bad_subwidg_type(false, ty);
12330 break;
12331 }
12332 }
12333 break;
12334 }
12335 case SUBWIDGTY_COLOR_BG:
12336 {
12337 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12338 {
12339 auto ty = widg->getType();
12340 switch(ty)
12341 {
12342 case widgTEXT:
12343 ret = 10000*((SW_Text*)widg)->c_bg.get_int_color();
12344 break;
12345 case widgTEXTBOX:
12346 ret = 10000*((SW_TextBox*)widg)->c_bg.get_int_color();
12347 break;
12348 case widgSELECTEDTEXT:
12349 ret = 10000*((SW_SelectedText*)widg)->c_bg.get_int_color();
12350 break;
12351 case widgTIME:
12352 ret = 10000*((SW_Time*)widg)->c_bg.get_int_color();
12353 break;
12354 case widgCOUNTER:
12355 ret = 10000*((SW_Counter*)widg)->c_bg.get_int_color();
12356 break;
12357 case widgBTNCOUNTER:
12358 ret = 10000*((SW_BtnCounter*)widg)->c_bg.get_int_color();
12359 break;
12360 case widgOLDCTR:
12361 ret = 10000*((SW_Counters*)widg)->c_bg.get_int_color();
12362 break;
12363 case widgMMAPTITLE:
12364 ret = 10000*((SW_MMapTitle*)widg)->c_bg.get_int_color();
12365 break;
12366 case widgBGCOLOR:
12367 ret = 10000*((SW_Clear*)widg)->c_bg.get_int_color();
12368 break;
12369 case widgCOUNTERPERCBAR:
12370 ret = 10000*((SW_CounterPercentBar*)widg)->c_bg.get_int_color();
12371 break;
12372 default:
12373 bad_subwidg_type(false, ty);
12374 break;
12375 }
12376 }
12377 break;
12378 }
12379
12380 case SUBWIDGTY_COLOR_TXT2:
12381 {
12382 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12383 {
12384 auto ty = widg->getType();
12385 switch(ty)
12386 {
12387 case widgCOUNTER:
12388 ret = 10000*((SW_Counter*)widg)->c_text2.get_int_color();
12389 break;
12390 case widgBTNCOUNTER:
12391 ret = 10000*((SW_BtnCounter*)widg)->c_text2.get_int_color();
12392 break;
12393 default:
12394 bad_subwidg_type(false, ty);
12395 break;
12396 }
12397 }
12398 break;
12399 }
12400 case SUBWIDGTY_COLOR_SHD2:
12401 {
12402 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12403 {
12404 auto ty = widg->getType();
12405 switch(ty)
12406 {
12407 case widgCOUNTER:
12408 ret = 10000*((SW_Counter*)widg)->c_shadow2.get_int_color();
12409 break;
12410 case widgBTNCOUNTER:
12411 ret = 10000*((SW_BtnCounter*)widg)->c_shadow2.get_int_color();
12412 break;
12413 default:
12414 bad_subwidg_type(false, ty);
12415 break;
12416 }
12417 }
12418 break;
12419 }
12420 case SUBWIDGTY_COLOR_BG2:
12421 {
12422 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12423 {
12424 auto ty = widg->getType();
12425 switch(ty)
12426 {
12427 case widgCOUNTER:
12428 ret = 10000*((SW_Counter*)widg)->c_bg2.get_int_color();
12429 break;
12430 case widgBTNCOUNTER:
12431 ret = 10000*((SW_BtnCounter*)widg)->c_bg2.get_int_color();
12432 break;
12433 default:
12434 bad_subwidg_type(false, ty);
12435 break;
12436 }
12437 }
12438 break;
12439 }
12440 case SUBWIDGTY_COLOR_OLINE:
12441 {
12442 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12443 {
12444 auto ty = widg->getType();
12445 switch(ty)
12446 {
12447 case widgLINE:
12448 ret = 10000*((SW_Line*)widg)->c_line.get_int_color();
12449 break;
12450 case widgRECT:
12451 ret = 10000*((SW_Rect*)widg)->c_outline.get_int_color();
12452 break;
12453 case widgMCGUFF_FRAME:
12454 ret = 10000*((SW_TriFrame*)widg)->c_outline.get_int_color();
12455 break;
12456 default:
12457 bad_subwidg_type(false, ty);
12458 break;
12459 }
12460 }
12461 break;
12462 }
12463 case SUBWIDGTY_COLOR_FILL:
12464 {
12465 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12466 {
12467 auto ty = widg->getType();
12468 switch(ty)
12469 {
12470 case widgRECT:
12471 ret = 10000*((SW_Rect*)widg)->c_fill.get_int_color();
12472 break;
12473 case widgCOUNTERPERCBAR:
12474 ret = 10000*((SW_CounterPercentBar*)widg)->c_fill.get_int_color();
12475 break;
12476 default:
12477 bad_subwidg_type(false, ty);
12478 break;
12479 }
12480 }
12481 break;
12482 }
12483 case SUBWIDGTY_BUTTON:
12484 {
12485 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12486 {
12487 auto ty = widg->getType();
12488 switch(ty)
12489 {
12490 case widgBTNITM:
12491 ret = 10000*((SW_ButtonItem*)widg)->btn;
12492 break;
12493 case widgBTNCOUNTER:
12494 ret = 10000*((SW_BtnCounter*)widg)->btn;
12495 break;
12496 default:
12497 bad_subwidg_type(false, ty);
12498 ret = -10000;
12499 break;
12500 }
12501 }
12502 break;
12503 }
12504 case SUBWIDGTY_COUNTERS:
12505 {
12506 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12507 {
12508 size_t indx = ri->d[rINDEX]/10000;
12509 size_t sz = 0;
12510 byte ty = widg->getType();
12511 switch(ty)
12512 {
12513 case widgCOUNTER:
12514 sz = 3;
12515 break;
12516 case widgMISCGAUGE: case widgCOUNTERPERCBAR:
12517 sz = 1;
12518 break;
12519 default:
12520 sz = 0;
12521 bad_subwidg_type(false, ty);
12522 ret = -10000;
12523 break;
12524 }
12525 if(!sz) break;
12526 if(indx >= sz)
12527 {
12528 Z_scripterrlog("Bad index '%d' to array "
12529 "'subscreenwidget->Counter[%d]'\n", indx, sz);
12530 break;
12531 }
12532 switch(ty)
12533 {
12534 case widgCOUNTER:
12535 ret = ((SW_Counter*)widg)->ctrs[indx]*10000;
12536 break;
12537 case widgMISCGAUGE:
12538 ret = ((SW_MiscGaugePiece*)widg)->counter*10000;
12539 break;
12540 case widgCOUNTERPERCBAR:
12541 ret = ((SW_CounterPercentBar*)widg)->counter*10000;
12542 break;
12543 }
12544 }
12545 break;
12546 }
12547 case SUBWIDGTY_MINDIG:
12548 {
12549 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12550 {
12551 auto ty = widg->getType();
12552 switch(ty)
12553 {
12554 case widgCOUNTER:
12555 ret = 10000*((SW_Counter*)widg)->mindigits;
12556 break;
12557 case widgBTNCOUNTER:
12558 ret = 10000*((SW_BtnCounter*)widg)->mindigits;
12559 break;
12560 case widgOLDCTR:
12561 ret = 10000*((SW_Counters*)widg)->digits;
12562 break;
12563 default:
12564 bad_subwidg_type(false, ty);
12565 ret = -10000;
12566 break;
12567 }
12568 }
12569 break;
12570 }
12571 case SUBWIDGTY_MAXDIG:
12572 {
12573 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12574 {
12575 auto ty = widg->getType();
12576 switch(ty)
12577 {
12578 case widgCOUNTER:
12579 ret = 10000*((SW_Counter*)widg)->maxdigits;
12580 break;
12581 case widgBTNCOUNTER:
12582 ret = 10000*((SW_BtnCounter*)widg)->maxdigits;
12583 break;
12584 default:
12585 bad_subwidg_type(false, ty);
12586 ret = -10000;
12587 break;
12588 }
12589 }
12590 break;
12591 }
12592 case SUBWIDGTY_INFITM:
12593 {
12594 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12595 {
12596 auto ty = widg->getType();
12597 switch(ty)
12598 {
12599 case widgCOUNTER:
12600 ret = 10000*((SW_Counter*)widg)->infitm;
12601 break;
12602 case widgOLDCTR:
12603 ret = 10000*((SW_Counters*)widg)->infitm;
12604 break;
12605 case widgLGAUGE:
12606 case widgMGAUGE:
12607 case widgMISCGAUGE:
12608 ret = 10000*((SW_GaugePiece*)widg)->inf_item;
12609 break;
12610 default:
12611 bad_subwidg_type(false, ty);
12612 ret = -10000;
12613 break;
12614 }
12615 }
12616 break;
12617 }
12618 case SUBWIDGTY_INFCHAR:
12619 {
12620 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12621 {
12622 auto ty = widg->getType();
12623 switch(ty)
12624 {
12625 case widgCOUNTER:
12626 ret = 10000*byte(((SW_Counter*)widg)->infchar);
12627 break;
12628 case widgOLDCTR:
12629 ret = 10000*byte(((SW_Counters*)widg)->infchar);
12630 break;
12631 case widgBTNCOUNTER:
12632 ret = 10000*byte(((SW_BtnCounter*)widg)->infchar);
12633 break;
12634 default:
12635 bad_subwidg_type(false, ty);
12636 break;
12637 }
12638 }
12639 break;
12640 }
12641 case SUBWIDGTY_COSTIND:
12642 {
12643 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12644 {
12645 auto ty = widg->getType();
12646 switch(ty)
12647 {
12648 case widgBTNCOUNTER:
12649 ret = 10000*((SW_BtnCounter*)widg)->costind;
12650 break;
12651 default:
12652 bad_subwidg_type(false, ty);
12653 ret = -1;
12654 break;
12655 }
12656 }
12657 break;
12658 }
12659 case SUBWIDGTY_COLOR_PLAYER:
12660 {
12661 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12662 {
12663 auto ty = widg->getType();
12664 switch(ty)
12665 {
12666 case widgMMAP:
12667 ret = 10000*((SW_MMap*)widg)->c_plr.get_int_color();
12668 break;
12669 case widgLMAP:
12670 ret = 10000*((SW_LMap*)widg)->c_plr.get_int_color();
12671 break;
12672 default:
12673 bad_subwidg_type(false, ty);
12674 break;
12675 }
12676 }
12677 break;
12678 }
12679 case SUBWIDGTY_COLOR_CMPBLNK:
12680 {
12681 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12682 {
12683 auto ty = widg->getType();
12684 switch(ty)
12685 {
12686 case widgMMAP:
12687 ret = 10000*((SW_MMap*)widg)->c_cmp_blink.get_int_color();
12688 break;
12689 default:
12690 bad_subwidg_type(false, ty);
12691 break;
12692 }
12693 }
12694 break;
12695 }
12696 case SUBWIDGTY_COLOR_CMPOFF:
12697 {
12698 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12699 {
12700 auto ty = widg->getType();
12701 switch(ty)
12702 {
12703 case widgMMAP:
12704 ret = 10000*((SW_MMap*)widg)->c_cmp_off.get_int_color();
12705 break;
12706 default:
12707 bad_subwidg_type(false, ty);
12708 break;
12709 }
12710 }
12711 break;
12712 }
12713 case SUBWIDGTY_COLOR_ROOM:
12714 {
12715 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12716 {
12717 auto ty = widg->getType();
12718 switch(ty)
12719 {
12720 case widgLMAP:
12721 ret = 10000*((SW_LMap*)widg)->c_room.get_int_color();
12722 break;
12723 default:
12724 bad_subwidg_type(false, ty);
12725 break;
12726 }
12727 }
12728 break;
12729 }
12730 case SUBWIDGTY_ITEMCLASS:
12731 {
12732 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12733 {
12734 auto ty = widg->getType();
12735 switch(ty)
12736 {
12737 case widgITEMSLOT:
12738 ret = 10000*((SW_ItemSlot*)widg)->iclass;
12739 break;
12740 default:
12741 bad_subwidg_type(false, ty);
12742 break;
12743 }
12744 }
12745 break;
12746 }
12747 case SUBWIDGTY_ITEMID:
12748 {
12749
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1455 times.
1455 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12750 {
12751 1455 auto ty = widg->getType();
12752
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1455 times.
1455 switch(ty)
12753 {
12754 case widgITEMSLOT:
12755 1455 ret = 10000*((SW_ItemSlot*)widg)->iid;
12756 1455 break;
12757 default:
12758 bad_subwidg_type(false, ty);
12759 break;
12760 }
12761 1455 }
12762 1455 break;
12763 }
12764 case SUBWIDGTY_FRAMETILE:
12765 {
12766 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12767 {
12768 auto ty = widg->getType();
12769 switch(ty)
12770 {
12771 case widgMCGUFF_FRAME:
12772 ret = 10000*((SW_TriFrame*)widg)->frame_tile;
12773 break;
12774 default:
12775 bad_subwidg_type(false, ty);
12776 break;
12777 }
12778 }
12779 break;
12780 }
12781 case SUBWIDGTY_FRAMECSET:
12782 {
12783 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12784 {
12785 auto ty = widg->getType();
12786 switch(ty)
12787 {
12788 case widgMCGUFF_FRAME:
12789 ret = 10000*((SW_TriFrame*)widg)->frame_cset;
12790 break;
12791 default:
12792 bad_subwidg_type(false, ty);
12793 break;
12794 }
12795 }
12796 break;
12797 }
12798 case SUBWIDGTY_PIECETILE:
12799 {
12800 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12801 {
12802 auto ty = widg->getType();
12803 switch(ty)
12804 {
12805 case widgMCGUFF_FRAME:
12806 ret = 10000*((SW_TriFrame*)widg)->piece_tile;
12807 break;
12808 default:
12809 bad_subwidg_type(false, ty);
12810 break;
12811 }
12812 }
12813 break;
12814 }
12815 case SUBWIDGTY_PIECECSET:
12816 {
12817 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12818 {
12819 auto ty = widg->getType();
12820 switch(ty)
12821 {
12822 case widgMCGUFF_FRAME:
12823 ret = 10000*((SW_TriFrame*)widg)->piece_cset;
12824 break;
12825 default:
12826 bad_subwidg_type(false, ty);
12827 break;
12828 }
12829 }
12830 break;
12831 }
12832 case SUBWIDGTY_FLIP:
12833 {
12834 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12835 {
12836 auto ty = widg->getType();
12837 switch(ty)
12838 {
12839 case widgMCGUFF:
12840 ret = 10000*((SW_McGuffin*)widg)->flip;
12841 break;
12842 case widgTILEBLOCK:
12843 ret = 10000*((SW_TileBlock*)widg)->flip;
12844 break;
12845 case widgMINITILE:
12846 ret = 10000*((SW_MiniTile*)widg)->flip;
12847 break;
12848 default:
12849 bad_subwidg_type(false, ty);
12850 break;
12851 }
12852 }
12853 break;
12854 }
12855 case SUBWIDGTY_NUMBER:
12856 {
12857 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12858 {
12859 auto ty = widg->getType();
12860 switch(ty)
12861 {
12862 case widgMCGUFF:
12863 ret = 10000*((SW_McGuffin*)widg)->number;
12864 break;
12865 default:
12866 bad_subwidg_type(false, ty);
12867 break;
12868 }
12869 }
12870 break;
12871 }
12872 case SUBWIDGTY_CORNER:
12873 {
12874 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12875 {
12876 size_t indx = ri->d[rINDEX]/10000;
12877 size_t sz = 0;
12878 byte ty = widg->getType();
12879 switch(ty)
12880 {
12881 case widgMINITILE:
12882 sz = 1;
12883 break;
12884 case widgLGAUGE:
12885 case widgMGAUGE:
12886 case widgMISCGAUGE:
12887 sz = 4;
12888 break;
12889 default:
12890 sz = 0;
12891 bad_subwidg_type(false, ty);
12892 ret = -10000;
12893 break;
12894 }
12895 if(!sz) break;
12896 if(indx >= sz)
12897 {
12898 Z_scripterrlog("Bad index '%d' to array "
12899 "'subscreenwidget->Corner[%d]'\n", indx, sz);
12900 break;
12901 }
12902 switch(ty)
12903 {
12904 case widgMINITILE:
12905 ret = 10000*((SW_MiniTile*)widg)->crn;
12906 break;
12907 case widgLGAUGE:
12908 case widgMGAUGE:
12909 case widgMISCGAUGE:
12910 ret = 10000*((SW_GaugePiece*)widg)->mts[indx].crn();
12911 break;
12912 }
12913 }
12914 break;
12915 }
12916 case SUBWIDGTY_FRAMES:
12917 {
12918 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12919 {
12920 auto ty = widg->getType();
12921 switch(ty)
12922 {
12923 case widgLGAUGE:
12924 case widgMGAUGE:
12925 case widgMISCGAUGE:
12926 ret = 10000*((SW_GaugePiece*)widg)->frames;
12927 break;
12928 default:
12929 bad_subwidg_type(false, ty);
12930 ret = -10000;
12931 break;
12932 }
12933 }
12934 break;
12935 }
12936 case SUBWIDGTY_SPEED:
12937 {
12938 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12939 {
12940 auto ty = widg->getType();
12941 switch(ty)
12942 {
12943 case widgLGAUGE:
12944 case widgMGAUGE:
12945 case widgMISCGAUGE:
12946 ret = 10000*((SW_GaugePiece*)widg)->speed;
12947 break;
12948 default:
12949 bad_subwidg_type(false, ty);
12950 ret = -10000;
12951 break;
12952 }
12953 }
12954 break;
12955 }
12956 case SUBWIDGTY_DELAY:
12957 {
12958 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12959 {
12960 auto ty = widg->getType();
12961 switch(ty)
12962 {
12963 case widgLGAUGE:
12964 case widgMGAUGE:
12965 case widgMISCGAUGE:
12966 ret = 10000*((SW_GaugePiece*)widg)->delay;
12967 break;
12968 default:
12969 bad_subwidg_type(false, ty);
12970 ret = -10000;
12971 break;
12972 }
12973 }
12974 break;
12975 }
12976 case SUBWIDGTY_CONTAINER:
12977 {
12978 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12979 {
12980 auto ty = widg->getType();
12981 switch(ty)
12982 {
12983 case widgLGAUGE:
12984 case widgMGAUGE:
12985 case widgMISCGAUGE:
12986 ret = 10000*((SW_GaugePiece*)widg)->container;
12987 break;
12988 default:
12989 bad_subwidg_type(false, ty);
12990 ret = -10000;
12991 break;
12992 }
12993 }
12994 break;
12995 }
12996 case SUBWIDGTY_GAUGE_WID:
12997 {
12998 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
12999 {
13000 auto ty = widg->getType();
13001 switch(ty)
13002 {
13003 case widgLGAUGE:
13004 case widgMGAUGE:
13005 case widgMISCGAUGE:
13006 ret = 10000*(((SW_GaugePiece*)widg)->gauge_wid+1);
13007 break;
13008 default:
13009 bad_subwidg_type(false, ty);
13010 ret = -10000;
13011 break;
13012 }
13013 }
13014 break;
13015 }
13016 case SUBWIDGTY_GAUGE_HEI:
13017 {
13018 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
13019 {
13020 auto ty = widg->getType();
13021 switch(ty)
13022 {
13023 case widgLGAUGE:
13024 case widgMGAUGE:
13025 case widgMISCGAUGE:
13026 ret = 10000*(((SW_GaugePiece*)widg)->gauge_hei+1);
13027 break;
13028 default:
13029 bad_subwidg_type(false, ty);
13030 ret = -10000;
13031 break;
13032 }
13033 }
13034 break;
13035 }
13036 case SUBWIDGTY_UNITS:
13037 {
13038 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
13039 {
13040 auto ty = widg->getType();
13041 switch(ty)
13042 {
13043 case widgLGAUGE:
13044 case widgMGAUGE:
13045 case widgMISCGAUGE:
13046 ret = 10000*(((SW_GaugePiece*)widg)->unit_per_frame+1);
13047 break;
13048 default:
13049 bad_subwidg_type(false, ty);
13050 ret = -10000;
13051 break;
13052 }
13053 }
13054 break;
13055 }
13056 case SUBWIDGTY_HSPACE:
13057 {
13058 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
13059 {
13060 auto ty = widg->getType();
13061 switch(ty)
13062 {
13063 case widgLGAUGE:
13064 case widgMGAUGE:
13065 case widgMISCGAUGE:
13066 ret = 10000*((SW_GaugePiece*)widg)->hspace;
13067 break;
13068 default:
13069 bad_subwidg_type(false, ty);
13070 ret = -10000;
13071 break;
13072 }
13073 }
13074 break;
13075 }
13076 case SUBWIDGTY_VSPACE:
13077 {
13078 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
13079 {
13080 auto ty = widg->getType();
13081 switch(ty)
13082 {
13083 case widgLGAUGE:
13084 case widgMGAUGE:
13085 case widgMISCGAUGE:
13086 ret = 10000*((SW_GaugePiece*)widg)->vspace;
13087 break;
13088 default:
13089 bad_subwidg_type(false, ty);
13090 ret = -10000;
13091 break;
13092 }
13093 }
13094 break;
13095 }
13096 case SUBWIDGTY_GRIDX:
13097 {
13098 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
13099 {
13100 auto ty = widg->getType();
13101 switch(ty)
13102 {
13103 case widgLGAUGE:
13104 case widgMGAUGE:
13105 case widgMISCGAUGE:
13106 ret = 10000*((SW_GaugePiece*)widg)->grid_xoff;
13107 break;
13108 default:
13109 bad_subwidg_type(false, ty);
13110 ret = -10000;
13111 break;
13112 }
13113 }
13114 break;
13115 }
13116 case SUBWIDGTY_GRIDY:
13117 {
13118 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
13119 {
13120 auto ty = widg->getType();
13121 switch(ty)
13122 {
13123 case widgLGAUGE:
13124 case widgMGAUGE:
13125 case widgMISCGAUGE:
13126 ret = 10000*((SW_GaugePiece*)widg)->grid_yoff;
13127 break;
13128 default:
13129 bad_subwidg_type(false, ty);
13130 ret = -10000;
13131 break;
13132 }
13133 }
13134 break;
13135 }
13136 case SUBWIDGTY_ANIMVAL:
13137 {
13138 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
13139 {
13140 auto ty = widg->getType();
13141 switch(ty)
13142 {
13143 case widgLGAUGE:
13144 case widgMGAUGE:
13145 case widgMISCGAUGE:
13146 ret = 10000*((SW_GaugePiece*)widg)->anim_val;
13147 break;
13148 default:
13149 bad_subwidg_type(false, ty);
13150 ret = -10000;
13151 break;
13152 }
13153 }
13154 break;
13155 }
13156 case SUBWIDGTY_SHOWDRAIN:
13157 {
13158 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
13159 {
13160 auto ty = widg->getType();
13161 switch(ty)
13162 {
13163 case widgMGAUGE:
13164 ret = 10000*((SW_MagicGaugePiece*)widg)->showdrain;
13165 break;
13166 default:
13167 bad_subwidg_type(false, ty);
13168 ret = -10000;
13169 break;
13170 }
13171 }
13172 break;
13173 }
13174 case SUBWIDGTY_PERCONTAINER:
13175 {
13176 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
13177 {
13178 auto ty = widg->getType();
13179 switch(ty)
13180 {
13181 case widgMISCGAUGE:
13182 ret = 10000*((SW_MiscGaugePiece*)widg)->per_container;
13183 break;
13184 default:
13185 bad_subwidg_type(false, ty);
13186 ret = -10000;
13187 break;
13188 }
13189 }
13190 break;
13191 }
13192 case SUBWIDGTY_TABSIZE:
13193 {
13194 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
13195 {
13196 auto ty = widg->getType();
13197 switch(ty)
13198 {
13199 case widgTEXTBOX:
13200 ret = 10000*((SW_TextBox*)widg)->tabsize;
13201 break;
13202 case widgSELECTEDTEXT:
13203 ret = 10000*((SW_SelectedText*)widg)->tabsize;
13204 break;
13205 default:
13206 bad_subwidg_type(false, ty);
13207 ret = -10000;
13208 break;
13209 }
13210 }
13211 break;
13212 }
13213 case SUBWIDGTY_LITEMS:
13214 {
13215 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
13216 {
13217 auto ty = widg->getType();
13218 switch(ty)
13219 {
13220 case widgMMAP:
13221 ret = 10000*((SW_MMap*)widg)->compass_litems;
13222 break;
13223 default:
13224 bad_subwidg_type(false, ty);
13225 ret = -10000;
13226 break;
13227 }
13228 }
13229 break;
13230 }
13231 ///----------------------------------------------------------------------------------------------------//
13232
13233 default:
13234 {
13235
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 281838972 times.
281838972 if (auto r = scripting_engine_get_register(arg))
13236 281838972 ret = *r;
13237 281838972 break;
13238 }
13239 }
13240
13241 2846197516 current_zasm_register = 0;
13242
13243 2846197516 return ret;
13244 3968278347 }
13245
13246 //Setter Instructions
13247
13248
13249 2111482080 void set_register(int32_t arg, int32_t value)
13250 {
13251
3/4
✓ Branch 0 taken 2111482080 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1622645152 times.
✓ Branch 3 taken 488836928 times.
2111482080 if (arg >= D(0) && arg <= D(7))
13252 {
13253 488836928 ri->d[arg - D(0)] = value;
13254 488836928 return;
13255 }
13256
4/4
✓ Branch 0 taken 1589111702 times.
✓ Branch 1 taken 33533450 times.
✓ Branch 2 taken 1589111474 times.
✓ Branch 3 taken 228 times.
1622645152 else if (arg >= GD(0) && arg <= GD(MAX_SCRIPT_REGISTERS))
13257 {
13258 228 game->global_d[arg-GD(0)] = value;
13259 228 return;
13260 }
13261
13262 //Macros
13263
13264 #define SET_SPRITEDATA_VAR_INT(member, str) \
13265 { \
13266 if(unsigned(ri->spritedataref) > (MAXWPNS-1) ) \
13267 { \
13268 Z_scripterrlog("Invalid Sprite ID passed to spritedata->%s: %d\n", str, (ri->spritedataref*10000)); \
13269 } \
13270 else \
13271 { \
13272 wpnsbuf[ri->spritedataref].member = vbound((value / 10000),0,214747); \
13273 } \
13274 } \
13275
13276 #define SET_SPRITEDATA_VAR_BYTE(member, str) \
13277 { \
13278 if(unsigned(ri->spritedataref) > (MAXWPNS-1) ) \
13279 { \
13280 Z_scripterrlog("Invalid Sprite ID passed to spritedata->%s: %d\n", str, (ri->spritedataref*10000)); \
13281 } \
13282 else \
13283 { \
13284 wpnsbuf[ri->spritedataref].member = vbound((value / 10000),0,255); \
13285 } \
13286 } \
13287
13288 1622644924 current_zasm_register = arg;
13289
13290 // Do not ever use `return` in these cases!
13291
261/1170
✗ Branch 0 not taken.
✓ Branch 1 taken 4499468 times.
✓ Branch 2 taken 14116 times.
✓ Branch 3 taken 2047856 times.
✓ Branch 4 taken 3675 times.
✓ Branch 5 taken 2299966 times.
✓ Branch 6 taken 2299127 times.
✓ Branch 7 taken 13913 times.
✓ Branch 8 taken 14191 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 14321 times.
✓ Branch 11 taken 16029 times.
✓ Branch 12 taken 527500 times.
✓ Branch 13 taken 4145 times.
✓ Branch 14 taken 4147 times.
✓ Branch 15 taken 13890 times.
✓ Branch 16 taken 13913 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 809 times.
✓ Branch 19 taken 17829 times.
✓ Branch 20 taken 26825 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 76581 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 2220 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 60 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 48 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✓ Branch 33 taken 837 times.
✓ Branch 34 taken 2288 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 718 times.
✓ Branch 37 taken 5878 times.
✓ Branch 38 taken 1 times.
✓ Branch 39 taken 73106 times.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✓ Branch 43 taken 26326 times.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✓ Branch 54 taken 3 times.
✓ Branch 55 taken 277656 times.
✓ Branch 56 taken 277656 times.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✓ Branch 60 taken 290 times.
✓ Branch 61 taken 4859 times.
✓ Branch 62 taken 3652 times.
✓ Branch 63 taken 2578 times.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✓ Branch 73 taken 194 times.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✓ Branch 76 taken 4 times.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✗ Branch 92 not taken.
✗ Branch 93 not taken.
✗ Branch 94 not taken.
✓ Branch 95 taken 1121819 times.
✓ Branch 96 taken 646198 times.
✓ Branch 97 taken 298036 times.
✓ Branch 98 taken 295303 times.
✓ Branch 99 taken 281941 times.
✓ Branch 100 taken 281894 times.
✓ Branch 101 taken 186826 times.
✓ Branch 102 taken 120700 times.
✓ Branch 103 taken 118163 times.
✓ Branch 104 taken 118214 times.
✓ Branch 105 taken 262073 times.
✓ Branch 106 taken 262073 times.
✓ Branch 107 taken 262073 times.
✓ Branch 108 taken 262073 times.
✗ Branch 109 not taken.
✗ Branch 110 not taken.
✗ Branch 111 not taken.
✗ Branch 112 not taken.
✓ Branch 113 taken 1121819 times.
✓ Branch 114 taken 646198 times.
✓ Branch 115 taken 261563 times.
✓ Branch 116 taken 261555 times.
✓ Branch 117 taken 261628 times.
✓ Branch 118 taken 261662 times.
✓ Branch 119 taken 177542 times.
✓ Branch 120 taken 111830 times.
✓ Branch 121 taken 115219 times.
✓ Branch 122 taken 115270 times.
✓ Branch 123 taken 262073 times.
✓ Branch 124 taken 262073 times.
✓ Branch 125 taken 262073 times.
✓ Branch 126 taken 262073 times.
✗ Branch 127 not taken.
✗ Branch 128 not taken.
✗ Branch 129 not taken.
✗ Branch 130 not taken.
✗ Branch 131 not taken.
✗ Branch 132 not taken.
✓ Branch 133 taken 2283 times.
✓ Branch 134 taken 1032651 times.
✓ Branch 135 taken 1041768 times.
✗ Branch 136 not taken.
✗ Branch 137 not taken.
✗ Branch 138 not taken.
✗ Branch 139 not taken.
✗ Branch 140 not taken.
✗ Branch 141 not taken.
✓ Branch 142 taken 54 times.
✗ Branch 143 not taken.
✗ Branch 144 not taken.
✗ Branch 145 not taken.
✗ Branch 146 not taken.
✗ Branch 147 not taken.
✗ Branch 148 not taken.
✗ Branch 149 not taken.
✗ Branch 150 not taken.
✗ Branch 151 not taken.
✗ Branch 152 not taken.
✗ Branch 153 not taken.
✗ Branch 154 not taken.
✗ Branch 155 not taken.
✗ Branch 156 not taken.
✗ Branch 157 not taken.
✗ Branch 158 not taken.
✓ Branch 159 taken 214057 times.
✓ Branch 160 taken 1 times.
✓ Branch 161 taken 214043 times.
✓ Branch 162 taken 971 times.
✓ Branch 163 taken 408 times.
✗ Branch 164 not taken.
✓ Branch 165 taken 71609 times.
✗ Branch 166 not taken.
✗ Branch 167 not taken.
✓ Branch 168 taken 9786 times.
✓ Branch 169 taken 1679 times.
✗ Branch 170 not taken.
✓ Branch 171 taken 6 times.
✓ Branch 172 taken 6 times.
✓ Branch 173 taken 1181 times.
✗ Branch 174 not taken.
✓ Branch 175 taken 1131 times.
✓ Branch 176 taken 476 times.
✓ Branch 177 taken 76041 times.
✓ Branch 178 taken 153795 times.
✗ Branch 179 not taken.
✓ Branch 180 taken 2464 times.
✓ Branch 181 taken 3263 times.
✗ Branch 182 not taken.
✓ Branch 183 taken 26540 times.
✓ Branch 184 taken 6 times.
✓ Branch 185 taken 429 times.
✓ Branch 186 taken 6 times.
✓ Branch 187 taken 527 times.
✓ Branch 188 taken 6 times.
✓ Branch 189 taken 885 times.
✓ Branch 190 taken 839 times.
✓ Branch 191 taken 2345 times.
✓ Branch 192 taken 6 times.
✓ Branch 193 taken 71310 times.
✓ Branch 194 taken 71308 times.
✓ Branch 195 taken 1768 times.
✓ Branch 196 taken 70954 times.
✗ Branch 197 not taken.
✗ Branch 198 not taken.
✗ Branch 199 not taken.
✓ Branch 200 taken 6 times.
✓ Branch 201 taken 72525 times.
✓ Branch 202 taken 72542 times.
✓ Branch 203 taken 6 times.
✓ Branch 204 taken 833 times.
✓ Branch 205 taken 833 times.
✓ Branch 206 taken 534237 times.
✓ Branch 207 taken 18928 times.
✗ Branch 208 not taken.
✓ Branch 209 taken 42 times.
✓ Branch 210 taken 12 times.
✓ Branch 211 taken 62002 times.
✓ Branch 212 taken 1130 times.
✗ Branch 213 not taken.
✓ Branch 214 taken 1210 times.
✗ Branch 215 not taken.
✗ Branch 216 not taken.
✗ Branch 217 not taken.
✗ Branch 218 not taken.
✗ Branch 219 not taken.
✓ Branch 220 taken 1042 times.
✗ Branch 221 not taken.
✗ Branch 222 not taken.
✗ Branch 223 not taken.
✓ Branch 224 taken 527 times.
✗ Branch 225 not taken.
✗ Branch 226 not taken.
✗ Branch 227 not taken.
✗ Branch 228 not taken.
✗ Branch 229 not taken.
✗ Branch 230 not taken.
✗ Branch 231 not taken.
✗ Branch 232 not taken.
✗ Branch 233 not taken.
✗ Branch 234 not taken.
✗ Branch 235 not taken.
✗ Branch 236 not taken.
✗ Branch 237 not taken.
✓ Branch 238 taken 390183 times.
✓ Branch 239 taken 1 times.
✓ Branch 240 taken 390780 times.
✓ Branch 241 taken 57530 times.
✓ Branch 242 taken 55587 times.
✗ Branch 243 not taken.
✓ Branch 244 taken 227256 times.
✓ Branch 245 taken 117 times.
✗ Branch 246 not taken.
✓ Branch 247 taken 372485 times.
✓ Branch 248 taken 220890 times.
✗ Branch 249 not taken.
✗ Branch 250 not taken.
✗ Branch 251 not taken.
✓ Branch 252 taken 208988 times.
✗ Branch 253 not taken.
✓ Branch 254 taken 5420 times.
✓ Branch 255 taken 12175 times.
✓ Branch 256 taken 210232 times.
✓ Branch 257 taken 114186 times.
✗ Branch 258 not taken.
✓ Branch 259 taken 74446 times.
✓ Branch 260 taken 178 times.
✗ Branch 261 not taken.
✓ Branch 262 taken 35337 times.
✗ Branch 263 not taken.
✓ Branch 264 taken 41 times.
✓ Branch 265 taken 1039 times.
✓ Branch 266 taken 549 times.
✓ Branch 267 taken 78832 times.
✓ Branch 268 taken 156969 times.
✓ Branch 269 taken 4552 times.
✗ Branch 270 not taken.
✓ Branch 271 taken 194229 times.
✓ Branch 272 taken 193736 times.
✓ Branch 273 taken 84994 times.
✓ Branch 274 taken 44193 times.
✗ Branch 275 not taken.
✗ Branch 276 not taken.
✗ Branch 277 not taken.
✓ Branch 278 taken 325611 times.
✓ Branch 279 taken 325024 times.
✓ Branch 280 taken 44 times.
✓ Branch 281 taken 202345 times.
✓ Branch 282 taken 202345 times.
✓ Branch 283 taken 2142027 times.
✓ Branch 284 taken 31616 times.
✗ Branch 285 not taken.
✗ Branch 286 not taken.
✗ Branch 287 not taken.
✓ Branch 288 taken 1621 times.
✓ Branch 289 taken 4504 times.
✗ Branch 290 not taken.
✗ Branch 291 not taken.
✗ Branch 292 not taken.
✗ Branch 293 not taken.
✗ Branch 294 not taken.
✗ Branch 295 not taken.
✗ Branch 296 not taken.
✗ Branch 297 not taken.
✗ Branch 298 not taken.
✓ Branch 299 taken 4 times.
✗ Branch 300 not taken.
✗ Branch 301 not taken.
✗ Branch 302 not taken.
✗ Branch 303 not taken.
✗ Branch 304 not taken.
✗ Branch 305 not taken.
✗ Branch 306 not taken.
✗ Branch 307 not taken.
✗ Branch 308 not taken.
✗ Branch 309 not taken.
✗ Branch 310 not taken.
✗ Branch 311 not taken.
✗ Branch 312 not taken.
✗ Branch 313 not taken.
✗ Branch 314 not taken.
✓ Branch 315 taken 6 times.
✓ Branch 316 taken 360 times.
✓ Branch 317 taken 360 times.
✗ Branch 318 not taken.
✗ Branch 319 not taken.
✗ Branch 320 not taken.
✗ Branch 321 not taken.
✗ Branch 322 not taken.
✗ Branch 323 not taken.
✗ Branch 324 not taken.
✗ Branch 325 not taken.
✗ Branch 326 not taken.
✗ Branch 327 not taken.
✗ Branch 328 not taken.
✗ Branch 329 not taken.
✗ Branch 330 not taken.
✗ Branch 331 not taken.
✗ Branch 332 not taken.
✗ Branch 333 not taken.
✗ Branch 334 not taken.
✗ Branch 335 not taken.
✗ Branch 336 not taken.
✗ Branch 337 not taken.
✗ Branch 338 not taken.
✗ Branch 339 not taken.
✓ Branch 340 taken 138 times.
✗ Branch 341 not taken.
✗ Branch 342 not taken.
✗ Branch 343 not taken.
✗ Branch 344 not taken.
✗ Branch 345 not taken.
✗ Branch 346 not taken.
✗ Branch 347 not taken.
✗ Branch 348 not taken.
✗ Branch 349 not taken.
✗ Branch 350 not taken.
✗ Branch 351 not taken.
✗ Branch 352 not taken.
✗ Branch 353 not taken.
✗ Branch 354 not taken.
✗ Branch 355 not taken.
✗ Branch 356 not taken.
✗ Branch 357 not taken.
✓ Branch 358 taken 128 times.
✓ Branch 359 taken 128 times.
✓ Branch 360 taken 128 times.
✗ Branch 361 not taken.
✗ Branch 362 not taken.
✗ Branch 363 not taken.
✗ Branch 364 not taken.
✓ Branch 365 taken 30 times.
✓ Branch 366 taken 30 times.
✗ Branch 367 not taken.
✗ Branch 368 not taken.
✗ Branch 369 not taken.
✗ Branch 370 not taken.
✗ Branch 371 not taken.
✗ Branch 372 not taken.
✓ Branch 373 taken 10 times.
✗ Branch 374 not taken.
✗ Branch 375 not taken.
✗ Branch 376 not taken.
✗ Branch 377 not taken.
✗ Branch 378 not taken.
✗ Branch 379 not taken.
✗ Branch 380 not taken.
✗ Branch 381 not taken.
✗ Branch 382 not taken.
✓ Branch 383 taken 27297 times.
✓ Branch 384 taken 536 times.
✗ Branch 385 not taken.
✗ Branch 386 not taken.
✓ Branch 387 taken 4 times.
✓ Branch 388 taken 900 times.
✓ Branch 389 taken 7396 times.
✓ Branch 390 taken 6502 times.
✗ Branch 391 not taken.
✓ Branch 392 taken 11 times.
✗ Branch 393 not taken.
✗ Branch 394 not taken.
✗ Branch 395 not taken.
✗ Branch 396 not taken.
✗ Branch 397 not taken.
✓ Branch 398 taken 5310 times.
✗ Branch 399 not taken.
✗ Branch 400 not taken.
✗ Branch 401 not taken.
✗ Branch 402 not taken.
✗ Branch 403 not taken.
✗ Branch 404 not taken.
✗ Branch 405 not taken.
✗ Branch 406 not taken.
✓ Branch 407 taken 17 times.
✓ Branch 408 taken 114 times.
✗ Branch 409 not taken.
✗ Branch 410 not taken.
✗ Branch 411 not taken.
✗ Branch 412 not taken.
✗ Branch 413 not taken.
✗ Branch 414 not taken.
✗ Branch 415 not taken.
✗ Branch 416 not taken.
✗ Branch 417 not taken.
✗ Branch 418 not taken.
✗ Branch 419 not taken.
✗ Branch 420 not taken.
✗ Branch 421 not taken.
✗ Branch 422 not taken.
✗ Branch 423 not taken.
✗ Branch 424 not taken.
✗ Branch 425 not taken.
✗ Branch 426 not taken.
✗ Branch 427 not taken.
✗ Branch 428 not taken.
✗ Branch 429 not taken.
✗ Branch 430 not taken.
✗ Branch 431 not taken.
✗ Branch 432 not taken.
✗ Branch 433 not taken.
✗ Branch 434 not taken.
✗ Branch 435 not taken.
✗ Branch 436 not taken.
✗ Branch 437 not taken.
✗ Branch 438 not taken.
✗ Branch 439 not taken.
✗ Branch 440 not taken.
✗ Branch 441 not taken.
✗ Branch 442 not taken.
✗ Branch 443 not taken.
✗ Branch 444 not taken.
✗ Branch 445 not taken.
✗ Branch 446 not taken.
✗ Branch 447 not taken.
✗ Branch 448 not taken.
✗ Branch 449 not taken.
✗ Branch 450 not taken.
✗ Branch 451 not taken.
✗ Branch 452 not taken.
✗ Branch 453 not taken.
✗ Branch 454 not taken.
✗ Branch 455 not taken.
✗ Branch 456 not taken.
✗ Branch 457 not taken.
✗ Branch 458 not taken.
✗ Branch 459 not taken.
✗ Branch 460 not taken.
✗ Branch 461 not taken.
✗ Branch 462 not taken.
✗ Branch 463 not taken.
✗ Branch 464 not taken.
✗ Branch 465 not taken.
✗ Branch 466 not taken.
✗ Branch 467 not taken.
✓ Branch 468 taken 20 times.
✗ Branch 469 not taken.
✗ Branch 470 not taken.
✗ Branch 471 not taken.
✗ Branch 472 not taken.
✗ Branch 473 not taken.
✗ Branch 474 not taken.
✗ Branch 475 not taken.
✓ Branch 476 taken 5120 times.
✗ Branch 477 not taken.
✗ Branch 478 not taken.
✗ Branch 479 not taken.
✗ Branch 480 not taken.
✗ Branch 481 not taken.
✗ Branch 482 not taken.
✗ Branch 483 not taken.
✗ Branch 484 not taken.
✗ Branch 485 not taken.
✓ Branch 486 taken 3225 times.
✗ Branch 487 not taken.
✗ Branch 488 not taken.
✗ Branch 489 not taken.
✗ Branch 490 not taken.
✗ Branch 491 not taken.
✗ Branch 492 not taken.
✗ Branch 493 not taken.
✓ Branch 494 taken 4 times.
✓ Branch 495 taken 2239361 times.
✓ Branch 496 taken 6367264 times.
✓ Branch 497 taken 12117377 times.
✓ Branch 498 taken 46788128 times.
✓ Branch 499 taken 162664378 times.
✓ Branch 500 taken 43204560 times.
✓ Branch 501 taken 88306945 times.
✗ Branch 502 not taken.
✓ Branch 503 taken 838813 times.
✓ Branch 504 taken 64 times.
✓ Branch 505 taken 410111 times.
✓ Branch 506 taken 1 times.
✓ Branch 507 taken 77218 times.
✗ Branch 508 not taken.
✓ Branch 509 taken 124 times.
✗ Branch 510 not taken.
✓ Branch 511 taken 10 times.
✗ Branch 512 not taken.
✗ Branch 513 not taken.
✓ Branch 514 taken 8474345 times.
✗ Branch 515 not taken.
✗ Branch 516 not taken.
✗ Branch 517 not taken.
✗ Branch 518 not taken.
✗ Branch 519 not taken.
✗ Branch 520 not taken.
✗ Branch 521 not taken.
✗ Branch 522 not taken.
✗ Branch 523 not taken.
✗ Branch 524 not taken.
✓ Branch 525 taken 284 times.
✗ Branch 526 not taken.
✗ Branch 527 not taken.
✓ Branch 528 taken 109743 times.
✓ Branch 529 taken 20806 times.
✓ Branch 530 taken 103742 times.
✓ Branch 531 taken 449481 times.
✗ Branch 532 not taken.
✓ Branch 533 taken 388 times.
✓ Branch 534 taken 120 times.
✓ Branch 535 taken 7263 times.
✗ Branch 536 not taken.
✗ Branch 537 not taken.
✗ Branch 538 not taken.
✓ Branch 539 taken 110 times.
✓ Branch 540 taken 38 times.
✗ Branch 541 not taken.
✗ Branch 542 not taken.
✗ Branch 543 not taken.
✗ Branch 544 not taken.
✗ Branch 545 not taken.
✗ Branch 546 not taken.
✗ Branch 547 not taken.
✗ Branch 548 not taken.
✗ Branch 549 not taken.
✗ Branch 550 not taken.
✗ Branch 551 not taken.
✗ Branch 552 not taken.
✗ Branch 553 not taken.
✗ Branch 554 not taken.
✗ Branch 555 not taken.
✗ Branch 556 not taken.
✗ Branch 557 not taken.
✗ Branch 558 not taken.
✗ Branch 559 not taken.
✗ Branch 560 not taken.
✗ Branch 561 not taken.
✗ Branch 562 not taken.
✗ Branch 563 not taken.
✗ Branch 564 not taken.
✗ Branch 565 not taken.
✗ Branch 566 not taken.
✓ Branch 567 taken 3 times.
✗ Branch 568 not taken.
✗ Branch 569 not taken.
✗ Branch 570 not taken.
✗ Branch 571 not taken.
✗ Branch 572 not taken.
✗ Branch 573 not taken.
✗ Branch 574 not taken.
✗ Branch 575 not taken.
✗ Branch 576 not taken.
✗ Branch 577 not taken.
✗ Branch 578 not taken.
✗ Branch 579 not taken.
✗ Branch 580 not taken.
✗ Branch 581 not taken.
✗ Branch 582 not taken.
✗ Branch 583 not taken.
✗ Branch 584 not taken.
✗ Branch 585 not taken.
✗ Branch 586 not taken.
✗ Branch 587 not taken.
✗ Branch 588 not taken.
✗ Branch 589 not taken.
✗ Branch 590 not taken.
✗ Branch 591 not taken.
✗ Branch 592 not taken.
✗ Branch 593 not taken.
✗ Branch 594 not taken.
✗ Branch 595 not taken.
✗ Branch 596 not taken.
✓ Branch 597 taken 11 times.
✗ Branch 598 not taken.
✓ Branch 599 taken 22 times.
✓ Branch 600 taken 11 times.
✓ Branch 601 taken 11 times.
✗ Branch 602 not taken.
✗ Branch 603 not taken.
✗ Branch 604 not taken.
✗ Branch 605 not taken.
✗ Branch 606 not taken.
✗ Branch 607 not taken.
✗ Branch 608 not taken.
✗ Branch 609 not taken.
✗ Branch 610 not taken.
✗ Branch 611 not taken.
✗ Branch 612 not taken.
✗ Branch 613 not taken.
✗ Branch 614 not taken.
✓ Branch 615 taken 132 times.
✓ Branch 616 taken 4247 times.
✗ Branch 617 not taken.
✗ Branch 618 not taken.
✗ Branch 619 not taken.
✗ Branch 620 not taken.
✗ Branch 621 not taken.
✗ Branch 622 not taken.
✗ Branch 623 not taken.
✗ Branch 624 not taken.
✗ Branch 625 not taken.
✗ Branch 626 not taken.
✗ Branch 627 not taken.
✗ Branch 628 not taken.
✗ Branch 629 not taken.
✗ Branch 630 not taken.
✗ Branch 631 not taken.
✗ Branch 632 not taken.
✗ Branch 633 not taken.
✗ Branch 634 not taken.
✗ Branch 635 not taken.
✗ Branch 636 not taken.
✗ Branch 637 not taken.
✗ Branch 638 not taken.
✗ Branch 639 not taken.
✗ Branch 640 not taken.
✗ Branch 641 not taken.
✗ Branch 642 not taken.
✗ Branch 643 not taken.
✗ Branch 644 not taken.
✗ Branch 645 not taken.
✗ Branch 646 not taken.
✗ Branch 647 not taken.
✗ Branch 648 not taken.
✗ Branch 649 not taken.
✗ Branch 650 not taken.
✗ Branch 651 not taken.
✗ Branch 652 not taken.
✗ Branch 653 not taken.
✗ Branch 654 not taken.
✗ Branch 655 not taken.
✗ Branch 656 not taken.
✗ Branch 657 not taken.
✗ Branch 658 not taken.
✗ Branch 659 not taken.
✗ Branch 660 not taken.
✗ Branch 661 not taken.
✗ Branch 662 not taken.
✗ Branch 663 not taken.
✗ Branch 664 not taken.
✗ Branch 665 not taken.
✗ Branch 666 not taken.
✗ Branch 667 not taken.
✗ Branch 668 not taken.
✗ Branch 669 not taken.
✗ Branch 670 not taken.
✗ Branch 671 not taken.
✗ Branch 672 not taken.
✗ Branch 673 not taken.
✗ Branch 674 not taken.
✗ Branch 675 not taken.
✗ Branch 676 not taken.
✗ Branch 677 not taken.
✗ Branch 678 not taken.
✗ Branch 679 not taken.
✗ Branch 680 not taken.
✗ Branch 681 not taken.
✗ Branch 682 not taken.
✗ Branch 683 not taken.
✗ Branch 684 not taken.
✗ Branch 685 not taken.
✗ Branch 686 not taken.
✗ Branch 687 not taken.
✗ Branch 688 not taken.
✗ Branch 689 not taken.
✗ Branch 690 not taken.
✗ Branch 691 not taken.
✗ Branch 692 not taken.
✗ Branch 693 not taken.
✗ Branch 694 not taken.
✗ Branch 695 not taken.
✓ Branch 696 taken 35323033 times.
✗ Branch 697 not taken.
✓ Branch 698 taken 13 times.
✓ Branch 699 taken 531793827 times.
✗ Branch 700 not taken.
✗ Branch 701 not taken.
✗ Branch 702 not taken.
✓ Branch 703 taken 477697 times.
✓ Branch 704 taken 497243 times.
✓ Branch 705 taken 2779 times.
✓ Branch 706 taken 97670 times.
✗ Branch 707 not taken.
✓ Branch 708 taken 283431 times.
✓ Branch 709 taken 14290 times.
✓ Branch 710 taken 5110 times.
✗ Branch 711 not taken.
✓ Branch 712 taken 952 times.
✓ Branch 713 taken 1638734 times.
✗ Branch 714 not taken.
✗ Branch 715 not taken.
✗ Branch 716 not taken.
✗ Branch 717 not taken.
✗ Branch 718 not taken.
✓ Branch 719 taken 388698 times.
✗ Branch 720 not taken.
✓ Branch 721 taken 93759 times.
✓ Branch 722 taken 93760 times.
✓ Branch 723 taken 93772 times.
✓ Branch 724 taken 93778 times.
✗ Branch 725 not taken.
✗ Branch 726 not taken.
✗ Branch 727 not taken.
✗ Branch 728 not taken.
✗ Branch 729 not taken.
✗ Branch 730 not taken.
✗ Branch 731 not taken.
✗ Branch 732 not taken.
✗ Branch 733 not taken.
✗ Branch 734 not taken.
✗ Branch 735 not taken.
✗ Branch 736 not taken.
✗ Branch 737 not taken.
✗ Branch 738 not taken.
✗ Branch 739 not taken.
✗ Branch 740 not taken.
✗ Branch 741 not taken.
✗ Branch 742 not taken.
✗ Branch 743 not taken.
✓ Branch 744 taken 2 times.
✗ Branch 745 not taken.
✗ Branch 746 not taken.
✗ Branch 747 not taken.
✗ Branch 748 not taken.
✗ Branch 749 not taken.
✗ Branch 750 not taken.
✗ Branch 751 not taken.
✗ Branch 752 not taken.
✗ Branch 753 not taken.
✗ Branch 754 not taken.
✗ Branch 755 not taken.
✗ Branch 756 not taken.
✗ Branch 757 not taken.
✗ Branch 758 not taken.
✗ Branch 759 not taken.
✗ Branch 760 not taken.
✗ Branch 761 not taken.
✗ Branch 762 not taken.
✗ Branch 763 not taken.
✗ Branch 764 not taken.
✗ Branch 765 not taken.
✗ Branch 766 not taken.
✗ Branch 767 not taken.
✗ Branch 768 not taken.
✗ Branch 769 not taken.
✗ Branch 770 not taken.
✗ Branch 771 not taken.
✗ Branch 772 not taken.
✗ Branch 773 not taken.
✓ Branch 774 taken 182 times.
✗ Branch 775 not taken.
✗ Branch 776 not taken.
✗ Branch 777 not taken.
✗ Branch 778 not taken.
✗ Branch 779 not taken.
✗ Branch 780 not taken.
✗ Branch 781 not taken.
✗ Branch 782 not taken.
✗ Branch 783 not taken.
✗ Branch 784 not taken.
✗ Branch 785 not taken.
✓ Branch 786 taken 2760 times.
✗ Branch 787 not taken.
✗ Branch 788 not taken.
✗ Branch 789 not taken.
✗ Branch 790 not taken.
✗ Branch 791 not taken.
✗ Branch 792 not taken.
✗ Branch 793 not taken.
✓ Branch 794 taken 94 times.
✗ Branch 795 not taken.
✓ Branch 796 taken 13 times.
✗ Branch 797 not taken.
✗ Branch 798 not taken.
✗ Branch 799 not taken.
✗ Branch 800 not taken.
✗ Branch 801 not taken.
✗ Branch 802 not taken.
✓ Branch 803 taken 4922 times.
✗ Branch 804 not taken.
✓ Branch 805 taken 41 times.
✓ Branch 806 taken 1104 times.
✓ Branch 807 taken 799 times.
✓ Branch 808 taken 2 times.
✗ Branch 809 not taken.
✗ Branch 810 not taken.
✗ Branch 811 not taken.
✗ Branch 812 not taken.
✗ Branch 813 not taken.
✗ Branch 814 not taken.
✗ Branch 815 not taken.
✗ Branch 816 not taken.
✗ Branch 817 not taken.
✗ Branch 818 not taken.
✗ Branch 819 not taken.
✗ Branch 820 not taken.
✗ Branch 821 not taken.
✓ Branch 822 taken 511648 times.
✓ Branch 823 taken 27516 times.
✓ Branch 824 taken 5233 times.
✓ Branch 825 taken 3646 times.
✗ Branch 826 not taken.
✓ Branch 827 taken 81346 times.
✗ Branch 828 not taken.
✓ Branch 829 taken 4 times.
✗ Branch 830 not taken.
✗ Branch 831 not taken.
✗ Branch 832 not taken.
✗ Branch 833 not taken.
✓ Branch 834 taken 103760 times.
✗ Branch 835 not taken.
✗ Branch 836 not taken.
✗ Branch 837 not taken.
✗ Branch 838 not taken.
✓ Branch 839 taken 2114 times.
✗ Branch 840 not taken.
✗ Branch 841 not taken.
✗ Branch 842 not taken.
✗ Branch 843 not taken.
✓ Branch 844 taken 26537 times.
✗ Branch 845 not taken.
✓ Branch 846 taken 39294 times.
✗ Branch 847 not taken.
✗ Branch 848 not taken.
✗ Branch 849 not taken.
✗ Branch 850 not taken.
✗ Branch 851 not taken.
✗ Branch 852 not taken.
✗ Branch 853 not taken.
✗ Branch 854 not taken.
✗ Branch 855 not taken.
✓ Branch 856 taken 370 times.
✗ Branch 857 not taken.
✗ Branch 858 not taken.
✗ Branch 859 not taken.
✗ Branch 860 not taken.
✗ Branch 861 not taken.
✗ Branch 862 not taken.
✗ Branch 863 not taken.
✗ Branch 864 not taken.
✗ Branch 865 not taken.
✗ Branch 866 not taken.
✗ Branch 867 not taken.
✗ Branch 868 not taken.
✗ Branch 869 not taken.
✗ Branch 870 not taken.
✗ Branch 871 not taken.
✗ Branch 872 not taken.
✗ Branch 873 not taken.
✗ Branch 874 not taken.
✗ Branch 875 not taken.
✗ Branch 876 not taken.
✗ Branch 877 not taken.
✗ Branch 878 not taken.
✗ Branch 879 not taken.
✗ Branch 880 not taken.
✗ Branch 881 not taken.
✗ Branch 882 not taken.
✗ Branch 883 not taken.
✗ Branch 884 not taken.
✗ Branch 885 not taken.
✗ Branch 886 not taken.
✗ Branch 887 not taken.
✓ Branch 888 taken 9 times.
✗ Branch 889 not taken.
✗ Branch 890 not taken.
✓ Branch 891 taken 245580 times.
✓ Branch 892 taken 154225 times.
✓ Branch 893 taken 56175 times.
✗ Branch 894 not taken.
✗ Branch 895 not taken.
✗ Branch 896 not taken.
✗ Branch 897 not taken.
✗ Branch 898 not taken.
✗ Branch 899 not taken.
✗ Branch 900 not taken.
✗ Branch 901 not taken.
✗ Branch 902 not taken.
✗ Branch 903 not taken.
✗ Branch 904 not taken.
✗ Branch 905 not taken.
✗ Branch 906 not taken.
✗ Branch 907 not taken.
✗ Branch 908 not taken.
✗ Branch 909 not taken.
✗ Branch 910 not taken.
✗ Branch 911 not taken.
✗ Branch 912 not taken.
✗ Branch 913 not taken.
✗ Branch 914 not taken.
✗ Branch 915 not taken.
✗ Branch 916 not taken.
✗ Branch 917 not taken.
✗ Branch 918 not taken.
✗ Branch 919 not taken.
✗ Branch 920 not taken.
✗ Branch 921 not taken.
✗ Branch 922 not taken.
✓ Branch 923 taken 28 times.
✗ Branch 924 not taken.
✗ Branch 925 not taken.
✗ Branch 926 not taken.
✗ Branch 927 not taken.
✓ Branch 928 taken 24 times.
✓ Branch 929 taken 24 times.
✗ Branch 930 not taken.
✗ Branch 931 not taken.
✓ Branch 932 taken 24 times.
✗ Branch 933 not taken.
✗ Branch 934 not taken.
✗ Branch 935 not taken.
✗ Branch 936 not taken.
✗ Branch 937 not taken.
✗ Branch 938 not taken.
✗ Branch 939 not taken.
✗ Branch 940 not taken.
✗ Branch 941 not taken.
✗ Branch 942 not taken.
✗ Branch 943 not taken.
✗ Branch 944 not taken.
✗ Branch 945 not taken.
✗ Branch 946 not taken.
✗ Branch 947 not taken.
✗ Branch 948 not taken.
✗ Branch 949 not taken.
✗ Branch 950 not taken.
✗ Branch 951 not taken.
✗ Branch 952 not taken.
✗ Branch 953 not taken.
✗ Branch 954 not taken.
✗ Branch 955 not taken.
✗ Branch 956 not taken.
✗ Branch 957 not taken.
✗ Branch 958 not taken.
✗ Branch 959 not taken.
✗ Branch 960 not taken.
✗ Branch 961 not taken.
✗ Branch 962 not taken.
✗ Branch 963 not taken.
✗ Branch 964 not taken.
✗ Branch 965 not taken.
✗ Branch 966 not taken.
✗ Branch 967 not taken.
✗ Branch 968 not taken.
✗ Branch 969 not taken.
✗ Branch 970 not taken.
✗ Branch 971 not taken.
✗ Branch 972 not taken.
✗ Branch 973 not taken.
✗ Branch 974 not taken.
✗ Branch 975 not taken.
✗ Branch 976 not taken.
✗ Branch 977 not taken.
✗ Branch 978 not taken.
✗ Branch 979 not taken.
✗ Branch 980 not taken.
✗ Branch 981 not taken.
✗ Branch 982 not taken.
✗ Branch 983 not taken.
✗ Branch 984 not taken.
✗ Branch 985 not taken.
✗ Branch 986 not taken.
✗ Branch 987 not taken.
✗ Branch 988 not taken.
✗ Branch 989 not taken.
✗ Branch 990 not taken.
✗ Branch 991 not taken.
✗ Branch 992 not taken.
✗ Branch 993 not taken.
✗ Branch 994 not taken.
✗ Branch 995 not taken.
✗ Branch 996 not taken.
✗ Branch 997 not taken.
✗ Branch 998 not taken.
✗ Branch 999 not taken.
✗ Branch 1000 not taken.
✗ Branch 1001 not taken.
✗ Branch 1002 not taken.
✗ Branch 1003 not taken.
✗ Branch 1004 not taken.
✗ Branch 1005 not taken.
✗ Branch 1006 not taken.
✗ Branch 1007 not taken.
✗ Branch 1008 not taken.
✗ Branch 1009 not taken.
✗ Branch 1010 not taken.
✗ Branch 1011 not taken.
✗ Branch 1012 not taken.
✗ Branch 1013 not taken.
✗ Branch 1014 not taken.
✗ Branch 1015 not taken.
✗ Branch 1016 not taken.
✗ Branch 1017 not taken.
✗ Branch 1018 not taken.
✗ Branch 1019 not taken.
✗ Branch 1020 not taken.
✗ Branch 1021 not taken.
✗ Branch 1022 not taken.
✗ Branch 1023 not taken.
✗ Branch 1024 not taken.
✗ Branch 1025 not taken.
✗ Branch 1026 not taken.
✗ Branch 1027 not taken.
✗ Branch 1028 not taken.
✗ Branch 1029 not taken.
✗ Branch 1030 not taken.
✗ Branch 1031 not taken.
✗ Branch 1032 not taken.
✗ Branch 1033 not taken.
✗ Branch 1034 not taken.
✗ Branch 1035 not taken.
✗ Branch 1036 not taken.
✗ Branch 1037 not taken.
✗ Branch 1038 not taken.
✗ Branch 1039 not taken.
✗ Branch 1040 not taken.
✗ Branch 1041 not taken.
✗ Branch 1042 not taken.
✗ Branch 1043 not taken.
✗ Branch 1044 not taken.
✗ Branch 1045 not taken.
✗ Branch 1046 not taken.
✗ Branch 1047 not taken.
✗ Branch 1048 not taken.
✗ Branch 1049 not taken.
✗ Branch 1050 not taken.
✗ Branch 1051 not taken.
✗ Branch 1052 not taken.
✗ Branch 1053 not taken.
✗ Branch 1054 not taken.
✗ Branch 1055 not taken.
✗ Branch 1056 not taken.
✗ Branch 1057 not taken.
✗ Branch 1058 not taken.
✗ Branch 1059 not taken.
✗ Branch 1060 not taken.
✗ Branch 1061 not taken.
✗ Branch 1062 not taken.
✗ Branch 1063 not taken.
✗ Branch 1064 not taken.
✗ Branch 1065 not taken.
✗ Branch 1066 not taken.
✗ Branch 1067 not taken.
✗ Branch 1068 not taken.
✗ Branch 1069 not taken.
✗ Branch 1070 not taken.
✗ Branch 1071 not taken.
✗ Branch 1072 not taken.
✗ Branch 1073 not taken.
✗ Branch 1074 not taken.
✗ Branch 1075 not taken.
✗ Branch 1076 not taken.
✗ Branch 1077 not taken.
✗ Branch 1078 not taken.
✗ Branch 1079 not taken.
✗ Branch 1080 not taken.
✗ Branch 1081 not taken.
✗ Branch 1082 not taken.
✗ Branch 1083 not taken.
✗ Branch 1084 not taken.
✗ Branch 1085 not taken.
✗ Branch 1086 not taken.
✗ Branch 1087 not taken.
✗ Branch 1088 not taken.
✗ Branch 1089 not taken.
✗ Branch 1090 not taken.
✗ Branch 1091 not taken.
✗ Branch 1092 not taken.
✗ Branch 1093 not taken.
✗ Branch 1094 not taken.
✗ Branch 1095 not taken.
✗ Branch 1096 not taken.
✗ Branch 1097 not taken.
✗ Branch 1098 not taken.
✗ Branch 1099 not taken.
✗ Branch 1100 not taken.
✗ Branch 1101 not taken.
✗ Branch 1102 not taken.
✗ Branch 1103 not taken.
✗ Branch 1104 not taken.
✗ Branch 1105 not taken.
✗ Branch 1106 not taken.
✗ Branch 1107 not taken.
✗ Branch 1108 not taken.
✗ Branch 1109 not taken.
✗ Branch 1110 not taken.
✗ Branch 1111 not taken.
✗ Branch 1112 not taken.
✗ Branch 1113 not taken.
✗ Branch 1114 not taken.
✗ Branch 1115 not taken.
✗ Branch 1116 not taken.
✗ Branch 1117 not taken.
✗ Branch 1118 not taken.
✗ Branch 1119 not taken.
✗ Branch 1120 not taken.
✗ Branch 1121 not taken.
✗ Branch 1122 not taken.
✗ Branch 1123 not taken.
✗ Branch 1124 not taken.
✗ Branch 1125 not taken.
✗ Branch 1126 not taken.
✗ Branch 1127 not taken.
✗ Branch 1128 not taken.
✗ Branch 1129 not taken.
✗ Branch 1130 not taken.
✗ Branch 1131 not taken.
✗ Branch 1132 not taken.
✗ Branch 1133 not taken.
✗ Branch 1134 not taken.
✗ Branch 1135 not taken.
✗ Branch 1136 not taken.
✗ Branch 1137 not taken.
✗ Branch 1138 not taken.
✗ Branch 1139 not taken.
✗ Branch 1140 not taken.
✗ Branch 1141 not taken.
✗ Branch 1142 not taken.
✗ Branch 1143 not taken.
✗ Branch 1144 not taken.
✗ Branch 1145 not taken.
✗ Branch 1146 not taken.
✗ Branch 1147 not taken.
✗ Branch 1148 not taken.
✗ Branch 1149 not taken.
✗ Branch 1150 not taken.
✗ Branch 1151 not taken.
✗ Branch 1152 not taken.
✗ Branch 1153 not taken.
✗ Branch 1154 not taken.
✗ Branch 1155 not taken.
✓ Branch 1156 taken 646324090 times.
✗ Branch 1157 not taken.
✗ Branch 1158 not taken.
✓ Branch 1159 taken 78 times.
✓ Branch 1160 taken 95 times.
✓ Branch 1161 taken 214459 times.
✗ Branch 1162 not taken.
✗ Branch 1163 not taken.
✗ Branch 1164 not taken.
✓ Branch 1165 taken 11 times.
✗ Branch 1166 not taken.
✓ Branch 1167 taken 102 times.
✗ Branch 1168 not taken.
✗ Branch 1169 not taken.
1622644924 switch(arg)
13292 {
13293 //debug ri->d[]
13294 case DEBUGD:
13295 {
13296 int32_t a = vbound((ri->d[rINDEX] / 10000), 0, 255);
13297 ri->d[a] = value/10000;
13298 break;
13299 }
13300
13301 ///----------------------------------------------------------------------------------------------------//
13302 //FFC Variables
13303 case DATA:
13304
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4499468 times.
4499468 if (auto ffc = ResolveFFC(ri->ffcref))
13305 {
13306 4499468 zc_ffc_set(*ffc, vbound(value/10000,0,MAXCOMBOS-1));
13307 4499468 }
13308 4499468 break;
13309
13310 case FFSCRIPT:
13311
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14116 times.
14116 if (auto ffc = ResolveFFC(ri->ffcref))
13312 {
13313 14116 ffc->script = vbound(value/10000, 0, NUMSCRIPTFFC-1);
13314
2/2
✓ Branch 0 taken 225856 times.
✓ Branch 1 taken 14116 times.
239972 for(int32_t i=0; i<16; i++)
13315 225856 ffc->miscellaneous[i] = 0;
13316
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14116 times.
14116 if (get_qr(qr_CLEARINITDONSCRIPTCHANGE))
13317 {
13318
2/2
✓ Branch 0 taken 112928 times.
✓ Branch 1 taken 14116 times.
127044 for(int32_t i=0; i<8; i++)
13319 112928 ffc->initd[i] = 0;
13320 14116 }
13321 14116 on_reassign_script_engine_data(ScriptType::FFC, ffc->index);
13322 14116 }
13323 14116 break;
13324
13325
13326 case FCSET:
13327
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2047856 times.
2047856 if (auto ffc = ResolveFFC(ri->ffcref))
13328 2047856 ffc->cset = (value/10000)&15;
13329 2047856 break;
13330
13331 case DELAY:
13332
2/2
✓ Branch 0 taken 3629 times.
✓ Branch 1 taken 46 times.
3675 if (auto ffc = ResolveFFC(ri->ffcref))
13333 3629 ffc->delay = value/10000;
13334 3675 break;
13335
13336 case FX:
13337
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2299966 times.
2299966 if (auto ffc = ResolveFFC(ri->ffcref))
13338 2299966 ffc->x = zslongToFix(value);
13339 2299966 break;
13340
13341 case FY:
13342
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2299127 times.
2299127 if (auto ffc = ResolveFFC(ri->ffcref))
13343 2299127 ffc->y=zslongToFix(value);
13344 2299127 break;
13345
13346 case XD:
13347
2/2
✓ Branch 0 taken 13867 times.
✓ Branch 1 taken 46 times.
13913 if (auto ffc = ResolveFFC(ri->ffcref))
13348 13867 ffc->vx=zslongToFix(value);
13349 13913 break;
13350
13351 case YD:
13352
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 14145 times.
14191 if (auto ffc = ResolveFFC(ri->ffcref))
13353 14145 ffc->vy=zslongToFix(value);
13354 14191 break;
13355
13356 case FFCID:
13357 break;
13358
13359 case XD2:
13360
2/2
✓ Branch 0 taken 14275 times.
✓ Branch 1 taken 46 times.
14321 if (auto ffc = ResolveFFC(ri->ffcref))
13361 14275 ffc->ax=zslongToFix(value);
13362 14321 break;
13363
13364 case YD2:
13365
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 15983 times.
16029 if (auto ffc = ResolveFFC(ri->ffcref))
13366 15983 ffc->ay=zslongToFix(value);
13367 16029 break;
13368
13369 case FFFLAGSD:
13370
2/2
✓ Branch 0 taken 506 times.
✓ Branch 1 taken 526994 times.
527500 if (auto ffc = ResolveFFC(ri->ffcref))
13371 {
13372 526994 ffc_flags flag = (ffc_flags)(1<<((ri->d[rINDEX])/10000));
13373
2/2
✓ Branch 0 taken 123892 times.
✓ Branch 1 taken 403102 times.
526994 SETFLAG(ffc->flags, flag, value);
13374
4/4
✓ Branch 0 taken 522907 times.
✓ Branch 1 taken 4087 times.
✓ Branch 2 taken 4402 times.
✓ Branch 3 taken 518505 times.
526994 if (flag == ffc_solid || flag == ffc_changer)
13375 8489 ffc->updateSolid();
13376 526994 }
13377 527500 break;
13378
13379 case FFCWIDTH:
13380
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 4099 times.
4145 if (auto ffc = ResolveFFC(ri->ffcref))
13381 4099 ffc->hit_width = (value/10000);
13382 4145 break;
13383
13384 case FFCHEIGHT:
13385
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 4101 times.
4147 if (auto ffc = ResolveFFC(ri->ffcref))
13386 4101 ffc->hit_height = (value/10000);
13387 4147 break;
13388
13389 case FFTWIDTH:
13390
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13890 times.
13890 if (auto ffc = ResolveFFC(ri->ffcref))
13391 13890 ffc->txsz = vbound(value/10000, 1, 4);
13392 13890 break;
13393
13394 case FFTHEIGHT:
13395
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13913 times.
13913 if (auto ffc = ResolveFFC(ri->ffcref))
13396 13913 ffc->tysz = vbound(value/10000, 1, 4);
13397 13913 break;
13398
13399 case FFCLAYER:
13400 if (auto ffc = ResolveFFC(ri->ffcref))
13401 ffc->layer = vbound(value/10000, 0, 7);
13402 break;
13403
13404 case FFLINK:
13405
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 763 times.
809 if (auto ffc = ResolveFFC(ri->ffcref))
13406 763 (ffc->link)=vbound(value/10000, 0, MAXFFCS-1); // Allow "ffc->Link = 0" to unlink ffc.
13407 //0 is none, setting this before made it impssible to clear it. -Z
13408 809 break;
13409
13410 case FFMISCD:
13411 {
13412 17829 int32_t a = vbound(ri->d[rINDEX]/10000,0,15);
13413
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17829 times.
17829 if (auto ffc = ResolveFFC(ri->ffcref))
13414 17829 ffc->miscellaneous[a]=value;
13415 17829 break;
13416 }
13417
13418 case FFINITDD:
13419
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26825 times.
26825 if (auto ffc = ResolveFFC(ri->ffcref))
13420 26825 (ffc->initd[vbound(ri->d[rINDEX]/10000,0,7)])=value;
13421 26825 break;
13422
13423 case FFCLASTCHANGERX:
13424 if (auto ffc = ResolveFFC(ri->ffcref) )
13425 ffc->changer_x=vbound(zslongToFix(value).getInt(),-32768, 32767);
13426 break;
13427
13428 case FFCLASTCHANGERY:
13429 if (auto ffc = ResolveFFC(ri->ffcref) )
13430 ffc->changer_y=vbound(zslongToFix(value).getInt(),-32768, 32767);
13431 break;
13432
13433
13434
13435 ///----------------------------------------------------------------------------------------------------//
13436 //Hero's Variables
13437 case LINKX:
13438 {
13439
2/2
✓ Branch 0 taken 23258 times.
✓ Branch 1 taken 454439 times.
477697 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
13440 {
13441 23258 Hero.setXfix(zslongToFix(value));
13442 23258 }
13443 else
13444 {
13445 454439 Hero.setX(value/10000);
13446 }
13447 }
13448 477697 break;
13449
13450 case LINKCSET:
13451 {
13452 Hero.cs = value/10000;
13453 break;
13454 }
13455 case LINKY:
13456 {
13457
2/2
✓ Branch 0 taken 22483 times.
✓ Branch 1 taken 474760 times.
497243 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
13458 {
13459 22483 Hero.setYfix(zslongToFix(value));
13460 22483 }
13461 else
13462 {
13463 474760 Hero.setY(value/10000);
13464 }
13465 }
13466 497243 break;
13467
13468 case LINKZ:
13469 {
13470
2/2
✓ Branch 0 taken 2775 times.
✓ Branch 1 taken 4 times.
2779 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
13471 {
13472 2775 Hero.setZfix(zslongToFix(value));
13473 2775 }
13474 else
13475 {
13476 4 Hero.setZ(value/10000);
13477 }
13478 }
13479 2779 break;
13480
13481 case LINKJUMP:
13482 76581 Hero.setFall(zslongToFix(value) * -100);
13483 76581 break;
13484
13485 case HEROFAKEJUMP:
13486 Hero.setFakeFall(zslongToFix(value) * -100);
13487 break;
13488
13489 case LINKDIR:
13490 {
13491 //Hero->setDir() calls reset_hookshot(), which removes the sword sprite.. O_o
13492
3/4
✓ Branch 0 taken 95484 times.
✓ Branch 1 taken 2186 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 95484 times.
97670 if(Hero.getAction() == attacking || Hero.getAction() == sideswimattacking) Hero.dir = (value/10000);
13493 95484 else Hero.setDir(value/10000);
13494
13495 97670 break;
13496 }
13497
13498 case LINKHITDIR:
13499 2220 Hero.setHitDir(value / 10000);
13500 2220 break;
13501
13502 case LINKGRAVITY:
13503 if(value)
13504 Hero.moveflags |= move_obeys_grav;
13505 else
13506 Hero.moveflags &= ~move_obeys_grav;
13507 break;
13508
13509 case HERONOSTEPFORWARD:
13510 FFCore.nostepforward = ( (value) ? 1 : 0 );
13511 break;
13512
13513 case LINKHP:
13514
6/6
✓ Branch 0 taken 177818 times.
✓ Branch 1 taken 105613 times.
✓ Branch 2 taken 283260 times.
✓ Branch 3 taken 171 times.
✓ Branch 4 taken 177647 times.
✓ Branch 5 taken 105613 times.
283431 game->set_life(zc_max(0, zc_min(value/10000,game->get_maxlife())));
13515 283431 break;
13516
13517 case LINKMP:
13518
6/6
✓ Branch 0 taken 6601 times.
✓ Branch 1 taken 7689 times.
✓ Branch 2 taken 14271 times.
✓ Branch 3 taken 19 times.
✓ Branch 4 taken 6582 times.
✓ Branch 5 taken 7689 times.
14290 game->set_magic(zc_max(0, zc_min(value/10000,game->get_maxmagic())));
13519 14290 break;
13520
13521 case LINKMAXHP:
13522 60 game->set_maxlife(value/10000);
13523 60 break;
13524
13525 case LINKMAXMP:
13526 game->set_maxmagic(value/10000);
13527 break;
13528
13529 case LINKACTION:
13530 {
13531 5110 int32_t act = value / 10000;
13532
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5110 times.
5110 switch(act)
13533 {
13534 case hookshotout:
13535 case stunned:
13536 case ispushing:
13537 FFCore.setHeroAction(act);
13538 break;
13539 default:
13540 5110 Hero.setAction((actiontype)(act));
13541 5110 }
13542 //Protect from writing illegal actions to Hero's raw variable.
13543 //in the future, we can move all scripted actions that are not possible
13544 //to set in ZC into this mechanic. -Z
13545 5110 break;
13546 }
13547
13548 case HEROHEALTHBEEP:
13549 {
13550 int32_t beep = vbound((value/10000),-4, 255);
13551 //-2 suspends system control of stopping the sound
13552 //-3 suspends system control of stopping the sound AND suspends
13553 // system control over starting or playing it.
13554 heart_beep_timer = beep;
13555 if ( heart_beep_timer > -1 )
13556 {
13557 cont_sfx(QMisc.miscsfx[sfxLOWHEART]);
13558 }
13559 else
13560 {
13561 stop_sfx(QMisc.miscsfx[sfxLOWHEART]);
13562 }
13563 break;
13564 }
13565
13566 case LINKHELD:
13567 48 Hero.setHeldItem(vbound(value/10000,0,MAXITEMS-1));
13568 48 break;
13569
13570 case HEROSTEPS:
13571 {
13572 lsteps[vbound(ri->d[rINDEX]/10000,0,7)] = value/10000;
13573 break;
13574 }
13575
13576 case HEROSTEPRATE:
13577
1/2
✓ Branch 0 taken 952 times.
✗ Branch 1 not taken.
952 if(!get_qr(qr_NEW_HERO_MOVEMENT))
13578 {
13579 Z_scripterrlog("To use '%s', you must %s the quest rule '%s'.", "Hero->Step", "enable", "New Hero Movement");
13580 }
13581
1/2
✓ Branch 0 taken 952 times.
✗ Branch 1 not taken.
952 Hero.setStepRate(zc_max(value/10000,0));
13582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 952 times.
952 if(!get_qr(qr_SCRIPT_WRITING_HEROSTEP_DOESNT_CARRY_OVER))
13583 952 zinit.heroStep = Hero.getStepRate();
13584 952 break;
13585 case HEROSHOVEOFFSET:
13586 if(!get_qr(qr_NEW_HERO_MOVEMENT2))
13587 Z_scripterrlog("To use 'Hero->ShoveOffset', you must enable the quest rule 'Newer Hero Movement'.");
13588 Hero.shove_offset = vbound(zslongToFix(value),16_zf,0_zf);
13589 if(!get_qr(qr_SCRIPT_WRITING_HEROSTEP_DOESNT_CARRY_OVER))
13590 zinit.shove_offset = Hero.shove_offset;
13591 break;
13592
13593 case LINKITEMD:
13594 {
13595 1638734 int32_t itemID=vbound(ri->d[rINDEX]/10000,0,MAXITEMS-1);
13596
13597 // If the Cane of Byrna is being removed, cancel its effect.
13598
3/4
✓ Branch 0 taken 1523342 times.
✓ Branch 1 taken 115392 times.
✓ Branch 2 taken 1523342 times.
✗ Branch 3 not taken.
1638734 if(value==0 && itemID==current_item_id(itype_cbyrna))
13599 stopCaneOfByrna();
13600
13601 1638734 auto& data = get_script_engine_data(ScriptType::Item, itemID);
13602
13603 //Stop current script if set false.
13604
4/4
✓ Branch 0 taken 1523342 times.
✓ Branch 1 taken 115392 times.
✓ Branch 2 taken 1523326 times.
✓ Branch 3 taken 16 times.
1638734 if ( !value && data.doscript )
13605 {
13606 16 data.doscript = 4; //Val of 4 means 'clear stack and quit'
13607 //itemScriptData[itemID].Clear(); //Don't clear here, causes crash if is current item!
13608 16 }
13609
4/4
✓ Branch 0 taken 115392 times.
✓ Branch 1 taken 1523326 times.
✓ Branch 2 taken 84 times.
✓ Branch 3 taken 115308 times.
1638718 else if ( value && !data.doscript )
13610 {
13611 //Clear the item refInfo and stack for use.
13612 115308 data.ref.Clear();
13613
1/2
✓ Branch 0 taken 115308 times.
✗ Branch 1 not taken.
115308 if ( (itemsbuf[itemID].flags&item_passive_script) ) data.doscript = 1;
13614 115308 }
13615
3/4
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 1523326 times.
✓ Branch 2 taken 84 times.
✗ Branch 3 not taken.
1523410 else if ( value && data.doscript == 4 )
13616 {
13617 // Arbitrary event number 49326: Writing the item false, then true, in the same frame. -Z
13618 if ( (itemsbuf[itemID].flags&item_passive_script) ) data.doscript = 1;
13619 }
13620
13621 1638734 bool settrue = ( value != 0 );
13622
13623 //Sanity check to prevent setting the item if the value would be the same. -Z
13624
2/2
✓ Branch 0 taken 1632841 times.
✓ Branch 1 taken 5893 times.
1638734 if ( game->item[itemID] != settrue )
13625 {
13626 5893 game->set_item(itemID,(value != 0));
13627 5893 }
13628
13629
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1638734 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1638734 if((get_qr(qr_OVERWORLDTUNIC) != 0) || (cur_screen<128 || dlevel))
13630 {
13631 1638734 ringcolor(false);
13632 //refreshpal=true;
13633 1638734 }
13634
2/2
✓ Branch 0 taken 115392 times.
✓ Branch 1 taken 1523342 times.
1638734 if ( !value ) //setting the item false clears the state of forced ->Equipment writes.
13635 {
13636
1/2
✓ Branch 0 taken 1523342 times.
✗ Branch 1 not taken.
1523342 if ( game->forced_bwpn == itemID )
13637 {
13638 game->forced_bwpn = -1;
13639 } //not else if! -Z
13640
2/2
✓ Branch 0 taken 1523341 times.
✓ Branch 1 taken 1 times.
1523342 if ( game->forced_awpn == itemID )
13641 {
13642 1 game->forced_awpn = -1;
13643 1 }
13644
2/2
✓ Branch 0 taken 1523339 times.
✓ Branch 1 taken 3 times.
1523342 if ( game->forced_xwpn == itemID )
13645 {
13646 3 game->forced_xwpn = -1;
13647 3 }
13648
2/2
✓ Branch 0 taken 1523339 times.
✓ Branch 1 taken 3 times.
1523342 if ( game->forced_ywpn == itemID )
13649 {
13650 3 game->forced_ywpn = -1;
13651 3 }
13652 1523342 }
13653 }
13654 1638734 break;
13655
13656 case LINKEQUIP:
13657 {
13658 if ( FFCore.getQuestHeaderInfo(vZelda) == 0x250 && FFCore.getQuestHeaderInfo(vBuild) < 33 )
13659 {
13660 break;
13661 }
13662 //int32_t seta = (value/10000) >> 8; int32_t setb = value/10000) & 0xFF;
13663 int32_t setb = ((value/10000)&0xFF00)>>8, seta = (value/10000)&0xFF;
13664 seta = vbound(seta,-1,255);
13665 setb = vbound(setb,-1,255);
13666
13667 Awpn = seta;
13668 game->awpn = 255;
13669 game->forced_awpn = seta;
13670 game->items_off[seta] = 0;
13671 directItemA = seta;
13672
13673 Bwpn = setb;
13674 game->bwpn = 255;
13675 game->forced_bwpn = setb;
13676 game->items_off[setb] = 0;
13677 directItemB = setb;
13678 break;
13679 }
13680
13681
13682 case SETITEMSLOT:
13683 {
13684 //ri->d[rINDEX2] = 1st arg
13685 //ri->d[rINDEX] = 2nd arg
13686 //value = third arg
13687 //int32_t item, int32_t slot, int32_t force
13688 int32_t itm = ri->d[rINDEX]/10000;
13689 itm = vbound(itm, -1, 255);
13690
13691 int32_t slot = ri->d[rINDEX2]/10000;
13692 int32_t force = ri->d[rEXP1]/10000;
13693
13694 //If we add more item buttons, slot should be an int32_t
13695 //and force shuld be an int32_t
13696
13697 /*
13698 For zScript,
13699 const int32_t ITM_REQUIRE_NONE = 0
13700 const int32_t ITM_REQUIRE_INVENTORY = 1
13701 const int32_t ITM_REQUIRE_A_SLOT_RULE = 2
13702 //Combine as flags
13703 */
13704 if ( force == 0 )
13705 {
13706 switch(slot)
13707 {
13708 case 0: //b
13709 Bwpn = itm;
13710 game->items_off[itm] = 0;
13711 game->bwpn = 255;
13712 game->forced_bwpn = itm;
13713 directItemB = itm;
13714 break;
13715
13716 case 1: //a
13717 Awpn = itm;
13718 game->items_off[itm] = 0;
13719 game->awpn = 255;
13720 game->forced_awpn = itm;
13721 directItemA = itm;
13722 break;
13723
13724 case 2: //x
13725 Xwpn = itm;
13726 game->items_off[itm] = 0;
13727 game->xwpn = 255;
13728 game->forced_xwpn = itm;
13729 directItemX = itm;
13730 break;
13731
13732 case 3: //y
13733 Ywpn = itm;
13734 game->items_off[itm] = 0;
13735 game->ywpn = 255;
13736 game->forced_ywpn = itm;
13737 directItemX = itm;
13738 break;
13739 }
13740 }
13741 else if ( force == 1 )
13742 {
13743 if (game->item[itm])
13744 {
13745 switch(slot)
13746 {
13747 case 0: //b
13748 Bwpn = itm;
13749 game->items_off[itm] = 0;
13750 game->bwpn = 255;
13751 game->forced_bwpn = itm;
13752 directItemB = itm;
13753 break;
13754
13755 case 1: //a
13756 Awpn = itm;
13757 game->items_off[itm] = 0;
13758 game->awpn = 255;
13759 game->forced_awpn = itm;
13760 directItemA = itm;
13761 break;
13762
13763 case 2: //x
13764 Xwpn = itm;
13765 game->items_off[itm] = 0;
13766 game->xwpn = 255;
13767 game->forced_xwpn = itm;
13768 directItemX = itm;
13769 break;
13770
13771 case 3: //y
13772 Ywpn = itm;
13773 game->items_off[itm] = 0;
13774 game->ywpn = 255;
13775 game->forced_ywpn = itm;
13776 directItemY = itm;
13777 break;
13778 }
13779 }
13780 }
13781 else if ( force == 2 )
13782 {
13783 switch(slot)
13784 {
13785 case 0: //b
13786 Bwpn = itm;
13787 game->items_off[itm] = 0;
13788 game->bwpn = 255;
13789 game->forced_bwpn = itm;
13790 directItemB = itm;
13791 break;
13792
13793 case 1: //a
13794 if (get_qr(qr_SELECTAWPN))
13795 {
13796 Awpn = itm;
13797 game->items_off[itm] = 0;
13798 game->awpn = 255;
13799 game->forced_awpn = itm;
13800 directItemA = itm;
13801 }
13802 break;
13803
13804 case 2: //x
13805 Xwpn = itm;
13806 game->items_off[itm] = 0;
13807 game->xwpn = 255;
13808 game->forced_xwpn = itm;
13809 directItemX = itm;
13810 break;
13811
13812 case 3: //y
13813 Ywpn = itm;
13814 game->items_off[itm] = 0;
13815 game->ywpn = 255;
13816 game->forced_ywpn = itm;
13817 directItemY = itm;
13818 break;
13819 }
13820 }
13821 else if ( force == 3 ) //Flag ITM_REQUIRE_INVENTORY + ITM_REQUIRE_SLOT_A_RULE
13822 {
13823 if ( game->item[itm] )
13824 {
13825 switch(slot)
13826 {
13827 case 0: //b
13828 Bwpn = itm;
13829 game->items_off[itm] = 0;
13830 game->bwpn = 255;
13831 game->forced_bwpn = itm;
13832 directItemB = itm;
13833 break;
13834
13835 case 1: //a
13836 if (get_qr(qr_SELECTAWPN))
13837 {
13838 Awpn = itm;
13839 game->items_off[itm] = 0;
13840 game->awpn = 255;
13841 game->forced_awpn = itm;
13842 directItemA = itm;
13843 }
13844 break;
13845
13846 case 2: //x
13847 Xwpn = itm;
13848 game->items_off[itm] = 0;
13849 game->xwpn = 255;
13850 game->forced_xwpn = itm;
13851 directItemX = itm;
13852 break;
13853
13854 case 3: //y
13855 Ywpn = itm;
13856 game->items_off[itm] = 0;
13857 game->ywpn = 255;
13858 game->forced_ywpn = itm;
13859 directItemY = itm;
13860 break;
13861 }
13862 }
13863 }
13864 }
13865 break;
13866
13867 case LINKINVIS:
13868 837 Hero.setDontDraw((value ? 2 : 0));
13869 837 break;
13870
13871 case LINKINVINC:
13872 2288 Hero.scriptcoldet=(value/10000);
13873 2288 break;
13874
13875 case LINKENGINEANIMATE:
13876 Hero.do_animation=value;
13877 break;
13878
13879 case LINKSWORDJINX:
13880 718 Hero.setSwordClk(value/10000);
13881 718 break;
13882
13883 case LINKITEMJINX:
13884 5878 Hero.setItemClk(value/10000);
13885 5878 break;
13886
13887 case LINKDRUNK:
13888 1 Hero.setDrunkClock(value/10000);
13889 1 break;
13890
13891 case LINKMISCD:
13892 73106 Hero.miscellaneous[vbound(ri->d[rINDEX]/10000,0,31)] = value;
13893 73106 break;
13894
13895 case LINKHITBY:
13896 {
13897 int32_t indx = ri->d[rINDEX]/10000;
13898 switch(indx)
13899 {
13900 //screen index objects
13901 case 0:
13902 case 1:
13903 case 2:
13904 case 3:
13905 case 8:
13906 case 9:
13907 case 10:
13908 case 11:
13909 case 12:
13910 case 16:
13911 {
13912 Hero.sethitHeroUID(indx, (value/10000)); //Why the Flidd did I vbound this? UIDs are LONGs, with a starting value of 0.0001. Why did I allow it, in fact? -Z
13913 break;
13914 }
13915 //UIDs
13916 case 4:
13917 case 5:
13918 case 6:
13919 case 7:
13920 case 13:
13921 case 14:
13922 case 15:
13923 {
13924 Hero.sethitHeroUID(indx, value); //Why the Flidd did I vbound this? UIDs are LONGs, with a starting value of 0.0001. Why did I allow it, in fact? -Z
13925 break;
13926 }
13927 default: { al_trace("Invalid index passed to Hero->HitBy[%d] /n", indx); break; }
13928 }
13929 break;
13930 }
13931
13932 case LINKDEFENCE:
13933 Hero.set_defence(vbound(ri->d[rINDEX]/10000,0,255), ((char)vbound((value/10000), 0, 255)));
13934 break;
13935
13936 case LINKHXOFS:
13937 (Hero.hxofs)=(zfix)(value/10000);
13938 break;
13939
13940 case LINKROTATION:
13941 if ( get_qr(qr_OLDSPRITEDRAWS) )
13942 {
13943 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
13944 break;
13945 }
13946 (Hero.rotation)=(value/10000);
13947 break;
13948
13949 case LINKSCALE:
13950 {
13951 if ( get_qr(qr_OLDSPRITEDRAWS) )
13952 {
13953 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
13954 break;
13955 }
13956 (Hero.scale)=(value/100.0);
13957 break;
13958 }
13959
13960 case LINKHYOFS:
13961 (Hero.hyofs)=(zfix)(value/10000);
13962 break;
13963
13964 case LINKXOFS:
13965 26326 (Hero.xofs)=(zfix)(value/10000);
13966 26326 break;
13967
13968 case LINKYOFS:
13969
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 388698 times.
388698 (Hero.yofs)=(zfix)(value/10000)+(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset);
13970 388698 break;
13971 case HEROTOTALDYOFFS:
13972 break; //READ-ONLY
13973
13974 case HEROSHADOWXOFS:
13975 (Hero.shadowxofs)=(zfix)(value/10000);
13976 break;
13977
13978 case HEROSHADOWYOFS:
13979 (Hero.shadowyofs)=(zfix)(value/10000);
13980 break;
13981
13982 case LINKZOFS:
13983 (Hero.zofs)=(zfix)(value/10000);
13984 break;
13985
13986 case LINKHXSZ:
13987 (Hero.hit_width)=(zfix)(value/10000);
13988 break;
13989
13990 case LINKHYSZ:
13991 (Hero.hit_height)=(zfix)(value/10000);
13992 break;
13993
13994 case LINKHZSZ:
13995 (Hero.hzsz)=(zfix)(value/10000);
13996 break;
13997
13998 case LINKTXSZ:
13999 (Hero.txsz)=(zfix)(value/10000);
14000 break;
14001
14002 case LINKTYSZ:
14003 (Hero.tysz)=(zfix)(value/10000);
14004 break;
14005
14006 case LINKTILE:
14007 (Hero.tile)=(zfix)(value/10000);
14008 break;
14009
14010 case LINKFLIP:
14011 (Hero.flip)=(zfix)(value/10000);
14012 break;
14013
14014
14015
14016 case LINKINVFRAME:
14017 3 Hero.setHClk( (int32_t)vbound((value/10000), 0, 214747) );
14018 3 break;
14019
14020 case LINKCANFLICKER:
14021 277656 Hero.setCanFlicker((value/10000)?1:0);
14022 277656 break;
14023
14024 case LINKHURTSFX:
14025 277656 Hero.setHurtSFX( (int32_t)vbound((value/10000), 0, 255) );
14026 277656 break;
14027
14028
14029 case LINKITEMB:
14030 {
14031
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93759 times.
93759 if ( value/10000 < -1 )
14032 {
14033 al_trace("Tried to write an invalid item ID to Hero->ItemB: %d\n",value/10000);
14034 break;
14035 }
14036
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93759 times.
93759 if ( value/10000 > MAXITEMS-1 )
14037 {
14038 al_trace("Tried to write an invalid item ID to Hero->ItemB: %d\n",value/10000);
14039 break;
14040 }
14041 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
14042
14043
2/2
✓ Branch 0 taken 93750 times.
✓ Branch 1 taken 9 times.
93759 if (Bwpn != (value/10000))
14044 {
14045 9 Bwpn = value/10000;
14046
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(new_subscreen_active)
14047 9 new_subscreen_active->get_page_pos(Bwpn, game->bwpn);
14048 9 game->forced_bwpn = value/10000;
14049 9 game->items_off[value/10000] = 0;
14050 9 }
14051 93759 directItemB = value/10000;
14052 93759 break;
14053 }
14054
14055
14056 case LINKITEMA:
14057 {
14058
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93760 times.
93760 if ( value/10000 < -1 )
14059 {
14060 Z_scripterrlog("Tried to write an invalid item ID to Hero->ItemA: %d\n",value/10000);
14061 break;
14062 }
14063
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93760 times.
93760 if ( value/10000 > MAXITEMS-1 )
14064 {
14065 Z_scripterrlog("Tried to write an invalid item ID to Hero->ItemA: %d\n",value/10000);
14066 break;
14067 }
14068 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
14069
2/2
✓ Branch 0 taken 93752 times.
✓ Branch 1 taken 8 times.
93760 if (Awpn != (value/10000))
14070 {
14071 8 Awpn = value/10000;
14072
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(new_subscreen_active)
14073 8 new_subscreen_active->get_page_pos(Awpn, game->awpn);
14074 8 game->items_off[value/10000] = 0;
14075 8 game->forced_awpn = value/10000;
14076 8 }
14077 93760 directItemA = value/10000;
14078 93760 break;
14079 }
14080
14081 case LINKITEMX:
14082 {
14083
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93772 times.
93772 if ( value/10000 < -1 )
14084 {
14085 Z_scripterrlog("Tried to write an invalid item ID to Hero->ItemX: %d\n",value/10000);
14086 break;
14087 }
14088
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93772 times.
93772 if ( value/10000 > MAXITEMS-1 )
14089 {
14090 Z_scripterrlog("Tried to write an invalid item ID to Hero->ItemX: %d\n",value/10000);
14091 break;
14092 }
14093 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
14094
2/2
✓ Branch 0 taken 93739 times.
✓ Branch 1 taken 33 times.
93772 if (Xwpn != (value/10000))
14095 {
14096 33 Xwpn = value/10000;
14097
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if(new_subscreen_active)
14098 33 new_subscreen_active->get_page_pos(Xwpn, game->xwpn);
14099 33 game->items_off[value/10000] = 0;
14100 33 game->forced_xwpn = value/10000;
14101 33 }
14102 93772 directItemX = value/10000;
14103 93772 break;
14104 }
14105 case LINKITEMY:
14106 {
14107
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93778 times.
93778 if ( value/10000 < -1 )
14108 {
14109 Z_scripterrlog("Tried to write an invalid item ID to Hero->ItemY: %d\n",value/10000);
14110 break;
14111 }
14112
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93778 times.
93778 if ( value/10000 > MAXITEMS-1 )
14113 {
14114 Z_scripterrlog("Tried to write an invalid item ID to Hero->ItemY: %d\n",value/10000);
14115 break;
14116 }
14117 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
14118
2/2
✓ Branch 0 taken 93735 times.
✓ Branch 1 taken 43 times.
93778 if (Ywpn != (value/10000))
14119 {
14120 43 Ywpn = value/10000;
14121
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 if(new_subscreen_active)
14122 43 new_subscreen_active->get_page_pos(Ywpn, game->ywpn);
14123 43 game->items_off[value/10000] = 0;
14124 43 game->forced_ywpn = value/10000;
14125 43 }
14126 93778 directItemY = value/10000;
14127 93778 break;
14128 }
14129
14130
14131 case LINKEATEN:
14132 Hero.setEaten(value/10000);
14133 break;
14134 case LINKGRABBED:
14135 Hero.inwallm = value != 0;
14136 break;
14137 case HEROBUNNY:
14138 Hero.setBunnyClock(value/10000);
14139 break;
14140 case LINKPUSH:
14141 Hero.pushing = zc_max((value/10000),0);
14142 break;
14143 case LINKSTUN:
14144 290 Hero.setStunClock(value/10000);
14145 290 break;
14146 case LINKSCRIPTTILE:
14147 4859 script_hero_sprite=vbound((value/10000), -1, NEWMAXTILES-1);
14148 4859 break;
14149
14150 case HEROSCRIPTCSET:
14151 3652 script_hero_cset=vbound((value/10000), -1, 0xF);
14152 3652 break;
14153 case LINKSCRIPFLIP:
14154 2578 script_hero_flip=vbound((value/10000),-1,256);
14155 2578 break;
14156
14157 case GAMESETA:
14158 {
14159 //int32_t state = (ri->d[rINDEX2]/10000);
14160 //int32_t extend = (ri->d[rINDEX2]/10000);
14161 //int32_t dir = (ri->d[rINDEX]/10000);
14162 // Z_message("Trying to force-set the A-button item().\n");
14163 // Hero.setAButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
14164 }
14165 break;
14166
14167 case GAMESETB:
14168 {
14169 //int32_t state = (ri->d[rINDEX2]/10000);
14170 //int32_t extend = (ri->d[rINDEX2]/10000);
14171 //int32_t dir = (ri->d[rINDEX]/10000);
14172 // Z_message("Trying to force-set the A-button item().\n");
14173 // Hero.setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
14174 }
14175 break;
14176
14177 //Set Hero Diagonal
14178 case LINKDIAG:
14179 Hero.setDiagMove(value?1:0);
14180 set_qr(qr_LTTPWALK, value?1:0);
14181 break;
14182
14183 //Set Hero Big Hitbox
14184 case LINKBIGHITBOX:
14185 Hero.setBigHitbox((value/10000)?1:0);
14186 set_qr(qr_LTTPCOLLISION, (value/10000)?1:0);
14187 break;
14188
14189 case LINKCLIMBING:
14190 Hero.setOnSideviewLadder(value!=0?true:false);
14191 break;
14192
14193 case HEROJUMPCOUNT:
14194 Hero.extra_jump_count = value/10000;
14195 break;
14196
14197 case HEROPULLCLK:
14198 Hero.pit_pullclk = value/10000;
14199 break;
14200 case HEROFALLCLK:
14201 {
14202 int32_t val = vbound(value/10000,0,70);
14203 if(val)
14204 Hero.setAction(falling);
14205 else if(Hero.action == falling)
14206 {
14207 Hero.setAction(none);
14208 }
14209 Hero.fallclk = val;
14210 break;
14211 }
14212 case HEROFALLCMB:
14213 Hero.fallCombo = vbound(value/10000,0,MAXCOMBOS-1);
14214 break;
14215 case HERODROWNCLK:
14216 {
14217 int32_t val = vbound(value/10000,0,70);
14218 if(val)
14219 {
14220 if (Hero.action != lavadrowning) Hero.setAction(drowning);
14221 }
14222 else if(Hero.action == drowning || Hero.action == lavadrowning)
14223 {
14224 Hero.setAction(none);
14225 }
14226 Hero.drownclk = val;
14227 break;
14228 }
14229 case HERODROWNCMB:
14230 Hero.drownCombo = vbound(value/10000,0,MAXCOMBOS-1);
14231 break;
14232 case HEROFAKEZ:
14233 {
14234 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
14235 {
14236 Hero.setFakeZfix(zslongToFix(value));
14237 }
14238 else
14239 {
14240 Hero.setFakeZ(value/10000);
14241 }
14242 }
14243 break;
14244 case HEROMOVEFLAGS:
14245 {
14246 194 int32_t indx = ri->d[rINDEX]/10000;
14247
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 194 times.
194 if(BC::checkIndex(indx, 0, 10) == SH::_NoError)
14248 {
14249 //All bits, in order, of a single byte; just use bitwise
14250 194 move_flags bit = (move_flags)(1<<indx);
14251
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 179 times.
194 if(value)
14252 15 Hero.moveflags |= bit;
14253 else
14254 179 Hero.moveflags &= ~bit;
14255 194 }
14256 194 break;
14257 }
14258 case HEROLIFTFLAGS:
14259 {
14260 int32_t indx = ri->d[rINDEX]/10000;
14261 if(BC::checkIndex(indx, 0, NUM_LIFTFL-1) == SH::_NoError)
14262 {
14263 lift_flags bit = (lift_flags)(1<<indx);
14264 if(value)
14265 Hero.liftflags |= bit;
14266 else
14267 Hero.liftflags &= ~bit;
14268 }
14269 break;
14270 }
14271
14272 case HEROSHIELDJINX:
14273 {
14274 Hero.shieldjinxclk = value / 10000;
14275 break;
14276 }
14277
14278 case CLOCKACTIVE:
14279 {
14280 4 Hero.setClock(watch=(value?true:false));
14281 4 break;
14282 }
14283
14284 case CLOCKCLK:
14285 clockclk = vbound((value/10000), 0, 214748);
14286 break;
14287
14288 case HERORESPAWNX:
14289 {
14290 zfix zx = zslongToFix(value);
14291 Hero.respawn_x = vbound(zx, 0_zf, 240_zf);
14292 break;
14293 }
14294
14295 case HERORESPAWNY:
14296 {
14297 zfix zy = zslongToFix(value);
14298 Hero.respawn_y = vbound(zy, 0_zf, 160_zf);
14299 break;
14300 }
14301
14302 case HERORESPAWNDMAP:
14303 {
14304 Hero.respawn_dmap = vbound(value/10000, 0, MAXDMAPS-1);
14305 break;
14306 }
14307
14308 case HERORESPAWNSCR:
14309 {
14310 Hero.respawn_scr = vbound(value/10000, 0, 0x7F);
14311 break;
14312 }
14313
14314
14315 case HEROSWITCHMAXTIMER:
14316 case HEROSWITCHTIMER:
14317 break; //read-only
14318
14319 case HEROIMMORTAL:
14320 {
14321 Hero.setImmortal(value/10000);
14322 break;
14323 }
14324
14325 case HEROCOYOTETIME:
14326 {
14327 auto v = value/10000;
14328 if(v < 0 || v > 65535) v = 65535;
14329 Hero.coyotetime = word(v);
14330 break;
14331 }
14332 case HEROLIFTEDWPN:
14333 {
14334 if(Hero.lift_wpn)
14335 {
14336 delete Hero.lift_wpn;
14337 Hero.lift_wpn = nullptr;
14338 }
14339 if(value)
14340 {
14341 if(weapon* wpn = checkLWpn(value))
14342 {
14343 if(wpn == Hero.lift_wpn) break;
14344 Hero.lift_wpn = wpn;
14345 if(Lwpns.find(wpn) > -1)
14346 Lwpns.remove(wpn);
14347 if(curScriptType == ScriptType::Lwpn && value == curScriptIndex)
14348 earlyretval = RUNSCRIPT_SELFREMOVE;
14349 }
14350 }
14351 break;
14352 }
14353 case HEROLIFTTIMER:
14354 {
14355 Hero.liftclk = value/10000;
14356 break;
14357 }
14358 case HEROLIFTMAXTIMER:
14359 {
14360 Hero.tliftclk = value/10000;
14361 break;
14362 }
14363 case HEROLIFTHEIGHT:
14364 {
14365 Hero.liftheight = zslongToFix(value);
14366 break;
14367 }
14368 case HEROHAMMERSTATE:
14369 {
14370 //readonly
14371 break;
14372 }
14373 case HEROFLICKERCOLOR:
14374 {
14375 Hero.flickercolor = value/10000;
14376 break;
14377 }
14378 case HEROFLICKERTRANSP:
14379 {
14380 Hero.flickertransp = value / 10000;
14381 break;
14382 }
14383 case HEROSCRICECMB:
14384 Hero.script_ice_combo = vbound(value/10000,-1,MAXCOMBOS); break;
14385 case HEROICEVX:
14386 Hero.ice_vx = zslongToFix(value); break;
14387 case HEROICEVY:
14388 Hero.ice_vy = zslongToFix(value); break;
14389 case HEROICEENTRYFRAMES:
14390 Hero.ice_entry_count = vbound(value/10000,0,255); break;
14391 case HEROICEENTRYMAXFRAMES:
14392 Hero.ice_entry_mcount = vbound(value/10000,0,255); break;
14393
14394
14395 ///----------------------------------------------------------------------------------------------------//
14396 //Input States
14397 case INPUTSTART:
14398 {
14399 1121819 control_state[6]=(value?true:false);
14400
2/2
✓ Branch 0 taken 1058724 times.
✓ Branch 1 taken 63095 times.
1121819 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[6]=false;
14401 1121819 break;
14402 }
14403
14404 case INPUTMAP:
14405 {
14406 646198 control_state[9]=(value?true:false);
14407
2/2
✓ Branch 0 taken 476961 times.
✓ Branch 1 taken 169237 times.
646198 if ( get_qr(qr_FIXDRUNKINPUTS) )
14408 169237 drunk_toggle_state[9]=false;
14409 646198 break;
14410 }
14411
14412 case INPUTUP:
14413 {
14414 298036 control_state[0]=(value?true:false);
14415
2/2
✓ Branch 0 taken 293445 times.
✓ Branch 1 taken 4591 times.
298036 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[0]=false;
14416 298036 break;
14417 }
14418
14419 case INPUTDOWN:
14420 {
14421 295303 control_state[1]=(value?true:false);
14422
2/2
✓ Branch 0 taken 290748 times.
✓ Branch 1 taken 4555 times.
295303 if ( get_qr(qr_FIXDRUNKINPUTS) )
14423 4555 drunk_toggle_state[1]=false;
14424 295303 break;
14425 }
14426
14427 case INPUTLEFT:
14428 {
14429 281941 control_state[2]=(value?true:false);
14430
2/2
✓ Branch 0 taken 277104 times.
✓ Branch 1 taken 4837 times.
281941 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[2]=false;
14431 281941 break;
14432 }
14433
14434 case INPUTRIGHT:
14435 {
14436 281894 control_state[3]=(value?true:false);
14437
2/2
✓ Branch 0 taken 277163 times.
✓ Branch 1 taken 4731 times.
281894 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[3]=false;
14438 281894 break;
14439 }
14440
14441 case INPUTA:
14442 {
14443 186826 control_state[4]=(value?true:false);
14444
2/2
✓ Branch 0 taken 142947 times.
✓ Branch 1 taken 43879 times.
186826 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[4]=false;
14445 186826 break;
14446 }
14447
14448 case INPUTB:
14449 {
14450 120700 control_state[5]=(value?true:false);
14451
2/2
✓ Branch 0 taken 116814 times.
✓ Branch 1 taken 3886 times.
120700 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[5]=false;
14452 120700 break;
14453 }
14454
14455 case INPUTL:
14456 {
14457 118163 control_state[7]=(value?true:false);
14458
2/2
✓ Branch 0 taken 116528 times.
✓ Branch 1 taken 1635 times.
118163 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[7]=false;
14459 118163 break;
14460 }
14461
14462 case INPUTR:
14463 {
14464 118214 control_state[8]=(value?true:false);
14465
2/2
✓ Branch 0 taken 116579 times.
✓ Branch 1 taken 1635 times.
118214 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[8]=false;
14466 118214 break;
14467 }
14468
14469 case INPUTEX1:
14470 {
14471 262073 control_state[10]=(value?true:false);
14472 262073 break;
14473 }
14474
14475 case INPUTEX2:
14476 262073 control_state[11]=(value?true:false);
14477 262073 break;
14478
14479 case INPUTEX3:
14480 262073 control_state[12]=(value?true:false);
14481 262073 break;
14482
14483 case INPUTEX4:
14484 262073 control_state[13]=(value?true:false);
14485 262073 break;
14486
14487 case INPUTAXISUP:
14488 control_state[14]=(value?true:false);
14489 break;
14490
14491 case INPUTAXISDOWN:
14492 control_state[15]=(value?true:false);
14493 break;
14494
14495 case INPUTAXISLEFT:
14496 control_state[16]=(value?true:false);
14497 break;
14498
14499 case INPUTAXISRIGHT:
14500 control_state[17]=(value?true:false);
14501 break;
14502
14503 case INPUTPRESSSTART:
14504 1121819 button_press[6]=(value?true:false);
14505 1121819 break;
14506
14507 case INPUTPRESSMAP:
14508 646198 button_press[9]=(value?true:false);
14509 646198 break;
14510
14511 case INPUTPRESSUP:
14512 261563 button_press[0]=(value?true:false);
14513 261563 break;
14514
14515 case INPUTPRESSDOWN:
14516 261555 button_press[1]=(value?true:false);
14517 261555 break;
14518
14519 case INPUTPRESSLEFT:
14520 261628 button_press[2]=(value?true:false);
14521 261628 break;
14522
14523 case INPUTPRESSRIGHT:
14524 261662 button_press[3]=(value?true:false);
14525 261662 break;
14526
14527 case INPUTPRESSA:
14528 177542 button_press[4]=(value?true:false);
14529 177542 break;
14530
14531 case INPUTPRESSB:
14532 111830 button_press[5]=(value?true:false);
14533 111830 break;
14534
14535 case INPUTPRESSL:
14536 115219 button_press[7]=(value?true:false);
14537 115219 break;
14538
14539 case INPUTPRESSR:
14540 115270 button_press[8]=(value?true:false);
14541 115270 break;
14542
14543 case INPUTPRESSEX1:
14544 262073 button_press[10]=(value?true:false);
14545 262073 break;
14546
14547 case INPUTPRESSEX2:
14548 262073 button_press[11]=(value?true:false);
14549 262073 break;
14550
14551 case INPUTPRESSEX3:
14552 262073 button_press[12]=(value?true:false);
14553 262073 break;
14554
14555 case INPUTPRESSEX4:
14556 262073 button_press[13]=(value?true:false);
14557 262073 break;
14558
14559 case PRESSAXISUP:
14560 button_press[14]=(value?true:false);
14561 break;
14562
14563 case PRESSAXISDOWN:
14564 button_press[15]=(value?true:false);
14565 break;
14566
14567 case PRESSAXISLEFT:
14568 button_press[16]=(value?true:false);
14569 break;
14570
14571 case PRESSAXISRIGHT:
14572 button_press[17]=(value?true:false);
14573 break;
14574
14575 case INPUTMOUSEX:
14576 {
14577 auto [x, y] = rti_game.local_to_world(value/10000, mouse_y);
14578 position_mouse(x, y);
14579 break;
14580 }
14581
14582 case INPUTMOUSEY:
14583 {
14584 int32_t mousequakeoffset = 56+((int32_t)(zc::math::Sin((double)(quakeclk*int64_t(2)-frame))*4));
14585 int32_t tempoffset = (quakeclk > 0) ? mousequakeoffset : (get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset);
14586 auto [x, y] = rti_game.local_to_world(mouse_x, value/10000 + tempoffset);
14587 position_mouse(x, y);
14588 break;
14589 }
14590
14591 case INPUTMOUSEZ:
14592 position_mouse_z(value/10000);
14593 break;
14594
14595 case FFRULE:
14596 {
14597 2283 int32_t ruleid = vbound((ri->d[rINDEX]/10000),0,qr_MAX);
14598 2283 set_qr(ruleid, (value?true:false));
14599 2283 apply_qr_rule(ruleid);
14600 }
14601 2283 break;
14602
14603 case BUTTONPRESS:
14604 // DUkey, DDkey, DLkey, DRkey, Akey, Bkey, Skey, Lkey, Rkey, Pkey, Exkey1, Exkey2, Exkey3, Exkey4 };
14605 {
14606 //Read-only
14607 1032651 int32_t button = vbound((ri->d[rINDEX]/10000),0,17);
14608 1032651 button_press[button]=(value?true:false);
14609
4/4
✓ Branch 0 taken 810105 times.
✓ Branch 1 taken 222546 times.
✓ Branch 2 taken 303930 times.
✓ Branch 3 taken 506175 times.
1032651 if ( button < 11 && get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[button]=false;
14610
14611 }
14612 1032651 break;
14613
14614 case BUTTONINPUT:
14615 {
14616 //Read-only
14617 1041768 int32_t button = vbound((ri->d[rINDEX]/10000),0,17);
14618 1041768 control_state[button]=(value?true:false);
14619
4/4
✓ Branch 0 taken 818469 times.
✓ Branch 1 taken 223299 times.
✓ Branch 2 taken 304102 times.
✓ Branch 3 taken 514367 times.
1041768 if ( button < 11 && get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[button]=false;
14620 }
14621 1041768 break;
14622
14623 case BUTTONHELD:
14624 {
14625 //Read-only
14626 int32_t button = vbound((ri->d[rINDEX]/10000),0,17);
14627 button_hold[button]=(value?true:false);
14628 }
14629 break;
14630
14631 case RAWKEY:
14632 {
14633 int32_t keyid = ri->d[rINDEX]/10000;
14634 if (write_array(key_current_frame, keyid, (bool)value))
14635 key[keyid] = _key[keyid] = (bool)value;
14636 }
14637 break;
14638
14639 case KEYINPUT:
14640 {
14641 write_array(KeyInput, ri->d[rINDEX]/10000, (value/10000)!=0);
14642 switch(ri->d[rINDEX]/10000)
14643 {
14644 case KEY_F6: onTryQuit(); break;
14645 case KEY_F3: Paused = !Paused; break;
14646 case KEY_F4: Paused = true; Advance = true; break;
14647 }
14648 break;
14649 }
14650 case KEYPRESS:
14651 {
14652 write_array(KeyPress, ri->d[rINDEX]/10000, (value/10000)!=0);
14653 break;
14654 }
14655
14656 case SIMULATEKEYPRESS:
14657 {
14658 //if ( !keypressed() ) break; //Don;t return values set by setting Hero->Input/Press
14659 //hmm...no, this won;t return properly for modifier keys.
14660 int32_t keyid = ri->d[rINDEX]/10000;
14661 //key = vbound(key,0,n);
14662 if (value/10000) simulate_keypress(keyid << 8);
14663 }
14664 break;
14665
14666 case KEYMODIFIERS:
14667 {
14668 key_shifts = ( value/10000 );
14669 break;
14670 }
14671
14672 case KEYBINDINGS:
14673 {
14674 int32_t keyid = ri->d[rINDEX]/10000;
14675 switch(keyid)
14676 {
14677 case 0: DUkey = ( value/10000 ); break;
14678 case 1: DDkey = ( value/10000 ); break;
14679 case 2: DLkey = ( value/10000 ); break;
14680 case 3: DRkey = ( value/10000 ); break;
14681 case 4: Akey = ( value/10000 ); break;
14682 case 5: Bkey = ( value/10000 ); break;
14683 case 6: Skey = ( value/10000 ); break;
14684 case 7: Lkey = ( value/10000 ); break;
14685 case 8: Rkey = ( value/10000 ); break;
14686 case 9: Pkey = ( value/10000 ); /*map*/ break;
14687 case 10: Exkey1 = ( value/10000 ); break;
14688 case 11: Exkey2 = ( value/10000 ); break;
14689 case 12: Exkey3 = ( value/10000 ); break;
14690 case 13: Exkey4 = ( value/10000 ); break;
14691
14692 default: { Z_scripterrlog("Invalid index [%d] passed to Input->KeyBindings[]\n", keyid); break; }
14693 }
14694 break;
14695 }
14696
14697 case DISABLEKEY:
14698 {
14699 //Input->DisableKey(int32_t key, bool disable)
14700 int32_t keyid = ri->d[rINDEX]/10000;
14701 switch (keyid)
14702 {
14703 case KEY_F7:
14704 case KEY_F8:
14705 case KEY_F9:
14706 Z_scripterrlog("The key %d passed to Input->DisableKey[] is system-reserved, and cannot be disabled\n", keyid);
14707 break;
14708
14709 default:
14710 write_array(disabledKeys, keyid, (bool)value);
14711 }
14712 break;
14713 }
14714
14715 case DISABLEBUTTON:
14716 {
14717 //Input->DisableButton(int32_t cb, bool disable)
14718 54 write_array(disable_control, ri->d[rINDEX]/10000, (bool)value);
14719 54 break;
14720 }
14721
14722 case MOUSEARR:
14723 {
14724 int32_t indx = (ri->d[rINDEX]/10000);
14725 switch (indx)
14726 {
14727 case 0: //MouseX
14728 {
14729 auto [x, y] = rti_game.local_to_world(value/10000, mouse_y);
14730 position_mouse(x, y);
14731 break;
14732 }
14733 case 1: //MouseY
14734 {
14735 int32_t mousequakeoffset = 56+((int32_t)(zc::math::Sin((double)(quakeclk*int64_t(2)-frame))*4));
14736 int32_t tempoffset = (quakeclk > 0) ? mousequakeoffset :(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset);
14737 auto [x, y] = rti_game.local_to_world(mouse_x, value/10000 + tempoffset);
14738 position_mouse(x, y);
14739 break;
14740
14741 }
14742 case 2: //MouseZ
14743 {
14744 position_mouse_z(value/10000);
14745 break;
14746 }
14747 case 3: //Left Click
14748 {
14749 if ( value ) mouse_b |= 1;
14750 else mouse_b &= ~1;
14751 break;
14752 }
14753 case 4: //Right Click
14754 {
14755 if ( value ) mouse_b |= 2;
14756 else mouse_b &= ~2;
14757 break;
14758 }
14759 case 5: //Middle Click
14760 {
14761 if ( value ) mouse_b |= 4;
14762 else mouse_b &= ~4;
14763 break;
14764 }
14765 default:
14766 {
14767 scripting_log_error_with_context("Invalid index: {}", indx);
14768 }
14769 }
14770
14771 }
14772 break;
14773
14774 ///----------------------------------------------------------------------------------------------------//
14775 //Itemdata Variables
14776 //not mine, but let;s guard some of them all the same -Z
14777 //item class
14778 case IDATAFAMILY:
14779 if(unsigned(ri->idata) >= MAXITEMS)
14780 {
14781 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14782 break;
14783 }
14784 (itemsbuf[ri->idata].family)=vbound(value/10000,0, 254);
14785 flushItemCache();
14786 break;
14787
14788 case IDATAUSEWPN:
14789 if(unsigned(ri->idata) >= MAXITEMS)
14790 {
14791 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14792 break;
14793 }
14794 (itemsbuf[ri->idata].useweapon)=vbound(value/10000, 0, 255);
14795 break;
14796 case IDATAUSEDEF:
14797 if(unsigned(ri->idata) >= MAXITEMS)
14798 {
14799 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14800 break;
14801 }
14802 (itemsbuf[ri->idata].usedefence)=vbound(value/10000, 0, 255);
14803 break;
14804 case IDATAWRANGE:
14805 if(unsigned(ri->idata) >= MAXITEMS)
14806 {
14807 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14808 break;
14809 }
14810 (itemsbuf[ri->idata].weaprange)=vbound(value/10000, 0, 255);
14811 break;
14812 case IDATAMAGICTIMER:
14813 if(unsigned(ri->idata) >= MAXITEMS)
14814 {
14815 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14816 break;
14817 }
14818 (itemsbuf[ri->idata].magiccosttimer[0])=vbound(value/10000, 0, 214747);
14819 break;
14820 case IDATAMAGICTIMER2:
14821 if(unsigned(ri->idata) >= MAXITEMS)
14822 {
14823 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14824 break;
14825 }
14826 (itemsbuf[ri->idata].magiccosttimer[1])=vbound(value/10000, 0, 214747);
14827 break;
14828 case IDATADURATION:
14829 if(unsigned(ri->idata) >= MAXITEMS)
14830 {
14831 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14832 break;
14833 }
14834 (itemsbuf[ri->idata].weapduration)=vbound(value/10000, 0, 255);
14835 break;
14836
14837 case IDATADUPLICATES:
14838 if(unsigned(ri->idata) >= MAXITEMS)
14839 {
14840 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14841 break;
14842 }
14843 (itemsbuf[ri->idata].duplicates)=vbound(value/10000, 0, 255);
14844 break;
14845 case IDATADRAWLAYER:
14846 if(unsigned(ri->idata) >= MAXITEMS)
14847 {
14848 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14849 break;
14850 }
14851 (itemsbuf[ri->idata].drawlayer)=vbound(value/10000, 0, 7);
14852 break;
14853 case IDATACOLLECTFLAGS:
14854 if(unsigned(ri->idata) >= MAXITEMS)
14855 {
14856 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14857 break;
14858 }
14859 //int32_t a = ri->d[rINDEX] / 10000;
14860 (itemsbuf[ri->idata].collectflags)=vbound(value/10000, 0, 214747);
14861 break;
14862 case IDATAWEAPONSCRIPT:
14863
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(unsigned(ri->idata) >= MAXITEMS)
14864 {
14865 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14866 break;
14867 }
14868 2 (itemsbuf[ri->idata].weaponscript)=vbound(value/10000, 0, 255);
14869 2 break;
14870 case IDATAMISCD:
14871 {
14872 if(unsigned(ri->idata) >= MAXITEMS)
14873 {
14874 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14875 break;
14876 }
14877 int32_t a = vbound((ri->d[rINDEX] / 10000),0,31);
14878 (itemsbuf[ri->idata].wpn_misc_d[a])=(value/10000);
14879 }
14880 break;
14881 case IDATAWPNINITD:
14882 {
14883 if(unsigned(ri->idata) >= MAXITEMS)
14884 {
14885 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14886 break;
14887 }
14888 int32_t a = vbound((ri->d[rINDEX] / 10000),0,7);
14889 (itemsbuf[ri->idata].weap_initiald[a])=(value);
14890 }
14891 break;
14892 case IDATAWEAPHXOFS:
14893 if(unsigned(ri->idata) >= MAXITEMS)
14894 {
14895 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14896 break;
14897 }
14898 (itemsbuf[ri->idata].weap_hxofs)=(value/10000);
14899 break;
14900 case IDATAWEAPHYOFS:
14901 if(unsigned(ri->idata) >= MAXITEMS)
14902 {
14903 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14904 break;
14905 }
14906 (itemsbuf[ri->idata].weap_hyofs)=(value/10000);
14907 break;
14908 case IDATAWEAPHXSZ:
14909 if(unsigned(ri->idata) >= MAXITEMS)
14910 {
14911 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14912 break;
14913 }
14914 (itemsbuf[ri->idata].weap_hxsz)=(value/10000);
14915 break;
14916 case IDATAWEAPHYSZ:
14917 if(unsigned(ri->idata) >= MAXITEMS)
14918 {
14919 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14920 break;
14921 }
14922 (itemsbuf[ri->idata].weap_hysz)=(value/10000);
14923 break;
14924 case IDATAWEAPHZSZ:
14925 if(unsigned(ri->idata) >= MAXITEMS)
14926 {
14927 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14928 break;
14929 }
14930 (itemsbuf[ri->idata].weap_hzsz)=(value/10000);
14931 break;
14932 case IDATAWEAPXOFS:
14933 if(unsigned(ri->idata) >= MAXITEMS)
14934 {
14935 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14936 break;
14937 }
14938 (itemsbuf[ri->idata].weap_xofs)=(value/10000);
14939 break;
14940 case IDATAWEAPYOFS:
14941 if(unsigned(ri->idata) >= MAXITEMS)
14942 {
14943 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14944 break;
14945 }
14946 (itemsbuf[ri->idata].weap_yofs)=(value/10000);
14947 break;
14948
14949
14950 case IDATAHXOFS:
14951 if(unsigned(ri->idata) >= MAXITEMS)
14952 {
14953 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14954 break;
14955 }
14956 (itemsbuf[ri->idata].hxofs)=(value/10000);
14957 break;
14958 case IDATAHYOFS:
14959 if(unsigned(ri->idata) >= MAXITEMS)
14960 {
14961 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14962 break;
14963 }
14964 (itemsbuf[ri->idata].hyofs)=(value/10000);
14965 break;
14966 case IDATAHXSZ:
14967 if(unsigned(ri->idata) >= MAXITEMS)
14968 {
14969 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14970 break;
14971 }
14972 (itemsbuf[ri->idata].hxsz)=(value/10000);
14973 break;
14974 case IDATAHYSZ:
14975 if(unsigned(ri->idata) >= MAXITEMS)
14976 {
14977 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14978 break;
14979 }
14980 (itemsbuf[ri->idata].hysz)=(value/10000);
14981 break;
14982 case IDATAHZSZ:
14983 if(unsigned(ri->idata) >= MAXITEMS)
14984 {
14985 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14986 break;
14987 }
14988 (itemsbuf[ri->idata].hzsz)=(value/10000);
14989 break;
14990 case IDATADXOFS:
14991 if(unsigned(ri->idata) >= MAXITEMS)
14992 {
14993 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
14994 break;
14995 }
14996 (itemsbuf[ri->idata].xofs)=(value/10000);
14997 break;
14998 case IDATADYOFS:
14999 if(unsigned(ri->idata) >= MAXITEMS)
15000 {
15001 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15002 break;
15003 }
15004 (itemsbuf[ri->idata].yofs)=(value/10000);
15005 break;
15006 case IDATATILEW:
15007 if(unsigned(ri->idata) >= MAXITEMS)
15008 {
15009 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15010 break;
15011 }
15012 (itemsbuf[ri->idata].tilew)=(value/10000);
15013 break;
15014 case IDATATILEH:
15015 if(unsigned(ri->idata) >= MAXITEMS)
15016 {
15017 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15018 break;
15019 }
15020 (itemsbuf[ri->idata].tileh)=(value/10000);
15021 break;
15022 case IDATAPICKUP:
15023 if(unsigned(ri->idata) >= MAXITEMS)
15024 {
15025 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15026 break;
15027 }
15028 (itemsbuf[ri->idata].pickup)=(value/10000);
15029 break;
15030 case IDATAOVERRIDEFL:
15031 if(unsigned(ri->idata) >= MAXITEMS)
15032 {
15033 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15034 break;
15035 }
15036 (itemsbuf[ri->idata].overrideFLAGS)=(value/10000);
15037 break;
15038
15039 case IDATATILEWWEAP:
15040 if(unsigned(ri->idata) >= MAXITEMS)
15041 {
15042 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15043 break;
15044 }
15045 (itemsbuf[ri->idata].weap_tilew)=(value/10000);
15046 break;
15047 case IDATATILEHWEAP:
15048 if(unsigned(ri->idata) >= MAXITEMS)
15049 {
15050 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15051 break;
15052 }
15053 (itemsbuf[ri->idata].weap_tileh)=(value/10000);
15054 break;
15055 case IDATAOVERRIDEFLWEAP:
15056 if(unsigned(ri->idata) >= MAXITEMS)
15057 {
15058 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15059 break;
15060 }
15061 (itemsbuf[ri->idata].weapoverrideFLAGS)=(value/10000);
15062 break;
15063
15064 case IDATAUSEMVT:
15065 {
15066 if(unsigned(ri->idata) >= MAXITEMS)
15067 {
15068 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15069 break;
15070 }
15071 int32_t a = vbound((ri->d[rINDEX] / 10000),0,(ITEM_MOVEMENT_PATTERNS-1));
15072 (itemsbuf[ri->idata].weap_pattern[a])=vbound(value/10000, 0, 255);
15073 break;
15074 }
15075
15076 case IDATALEVEL:
15077 if(unsigned(ri->idata) >= MAXITEMS)
15078 {
15079 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15080 break;
15081 }
15082 (itemsbuf[ri->idata].fam_type)=vbound(value/10000, 0, 512);
15083 flushItemCache();
15084 break;
15085 case IDATAKEEP:
15086 item_flag(item_gamedata, value);
15087 break;
15088 case IDATAAMOUNT:
15089 {
15090 if(unsigned(ri->idata) >= MAXITEMS)
15091 {
15092 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15093 break;
15094 }
15095 int32_t v = vbound(value/10000, -9999, 16383);
15096 itemsbuf[ri->idata].amount &= 0x8000;
15097 itemsbuf[ri->idata].amount |= (abs(v)&0x3FFF)|(v<0?0x4000:0);
15098 break;
15099 }
15100 case IDATAGRADUAL:
15101 {
15102 if(unsigned(ri->idata) >= MAXITEMS)
15103 {
15104 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15105 break;
15106 }
15107 SETFLAG(itemsbuf[ri->idata].amount, 0x8000, value!=0);
15108 break;
15109 }
15110 case IDATACONSTSCRIPT:
15111 item_flag(item_passive_script, value);
15112 break;
15113 case IDATASSWIMDISABLED:
15114 item_flag(item_sideswim_disabled, value);
15115 break;
15116 case IDATABUNNYABLE:
15117 item_flag(item_bunny_enabled, value);
15118 break;
15119 case IDATAJINXIMMUNE:
15120 item_flag(item_jinx_immune, value);
15121 break;
15122 case IDATAJINXSWAP:
15123 item_flag(item_flip_jinx, value);
15124 break;
15125 case IDATAUSEBURNSPR:
15126 item_flag(item_burning_sprites, value);
15127 break;
15128 case IDATASETMAX:
15129 if(unsigned(ri->idata) >= MAXITEMS)
15130 {
15131 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15132 break;
15133 }
15134 (itemsbuf[ri->idata].setmax)=value/10000;
15135 break;
15136
15137 case IDATAMAX:
15138 if(unsigned(ri->idata) >= MAXITEMS)
15139 {
15140 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15141 break;
15142 }
15143 (itemsbuf[ri->idata].max)=value/10000;
15144 break;
15145
15146 case IDATAPOWER:
15147
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 182 times.
182 if(unsigned(ri->idata) >= MAXITEMS)
15148 {
15149 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15150 break;
15151 }
15152 182 (itemsbuf[ri->idata].power)=value/10000;
15153 182 break;
15154
15155 case IDATACOUNTER:
15156 if(unsigned(ri->idata) >= MAXITEMS)
15157 {
15158 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15159 break;
15160 }
15161 (itemsbuf[ri->idata].count)=vbound(value/10000,0,31);
15162 break;
15163
15164 case IDATAPSOUND:
15165 if(unsigned(ri->idata) >= MAXITEMS)
15166 {
15167 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15168 break;
15169 }
15170 (itemsbuf[ri->idata].playsound)=vbound(value/10000, 0, 255);
15171 break;
15172
15173 case IDATAUSESOUND:
15174 if(unsigned(ri->idata) >= MAXITEMS)
15175 {
15176 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15177 break;
15178 }
15179 (itemsbuf[ri->idata].usesound)=vbound(value/10000, 0, 255);
15180 break;
15181
15182 case IDATAUSESOUND2:
15183 if(unsigned(ri->idata) >= MAXITEMS)
15184 {
15185 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15186 break;
15187 }
15188 (itemsbuf[ri->idata].usesound2)=vbound(value/10000, 0, 255);
15189 break;
15190
15191 //2.54
15192 //My additions begin here. -Z
15193 //Stack item to gain next level
15194 case IDATACOMBINE:
15195 item_flag(item_combine, value);
15196 break;
15197 //using a level of an item downgrades to a lower one
15198 case IDATADOWNGRADE:
15199 item_flag(item_downgrade, value);
15200 break;
15201 //Only validate the cost, don't charge it
15202 case IDATAVALIDATE:
15203 item_flag(item_validate_only, value);
15204 break;
15205 case IDATAVALIDATE2:
15206 item_flag(item_validate_only_2, value);
15207 break;
15208
15209 //Flags[5]
15210 case IDATAFLAGS:
15211 {
15212 if(unsigned(ri->idata) >= MAXITEMS)
15213 {
15214 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15215 break;
15216 }
15217 int32_t index = ri->d[rINDEX]/10000;
15218 switch(index)
15219 {
15220 case 0:
15221 SETFLAG(itemsbuf[ri->idata].flags, item_flag1, value);
15222 break;
15223 case 1:
15224 SETFLAG(itemsbuf[ri->idata].flags, item_flag2, value);
15225 break;
15226 case 2:
15227 SETFLAG(itemsbuf[ri->idata].flags, item_flag3, value);
15228 break;
15229 case 3:
15230 SETFLAG(itemsbuf[ri->idata].flags, item_flag4, value);
15231 break;
15232 case 4:
15233 SETFLAG(itemsbuf[ri->idata].flags, item_flag5, value);
15234 break;
15235 case 5:
15236 SETFLAG(itemsbuf[ri->idata].flags, item_flag6, value);
15237 break;
15238 case 6:
15239 SETFLAG(itemsbuf[ri->idata].flags, item_flag7, value);
15240 break;
15241 case 7:
15242 SETFLAG(itemsbuf[ri->idata].flags, item_flag8, value);
15243 break;
15244 case 8:
15245 SETFLAG(itemsbuf[ri->idata].flags, item_flag9, value);
15246 cache_tile_mod_clear();
15247 break;
15248 case 9:
15249 SETFLAG(itemsbuf[ri->idata].flags, item_flag10, value);
15250 break;
15251 case 10:
15252 SETFLAG(itemsbuf[ri->idata].flags, item_flag11, value);
15253 break;
15254 case 11:
15255 SETFLAG(itemsbuf[ri->idata].flags, item_flag12, value);
15256 break;
15257 case 12:
15258 SETFLAG(itemsbuf[ri->idata].flags, item_flag13, value);
15259 break;
15260 case 13:
15261 SETFLAG(itemsbuf[ri->idata].flags, item_flag14, value);
15262 break;
15263 case 14:
15264 SETFLAG(itemsbuf[ri->idata].flags, item_flag15, value);
15265 break;
15266 case 15:
15267 SETFLAG(itemsbuf[ri->idata].flags, item_passive_script, value);
15268 break;
15269 }
15270
15271 break;
15272 }
15273 //Keep Old in editor
15274 case IDATAKEEPOLD:
15275 item_flag(item_keep_old, value);
15276 break;
15277 //Ruppes for magic
15278 case IDATARUPEECOST:
15279 item_flag(item_rupee_magic, value);
15280 break;
15281 //can be eaten
15282 case IDATAEDIBLE:
15283 item_flag(item_edible, value);
15284 break;
15285 //Unused at this time
15286 case IDATAFLAGUNUSED:
15287 item_flag(item_unused, value);
15288 break;
15289 //gain lower level items
15290 case IDATAGAINLOWER:
15291 item_flag(item_gain_old, value);
15292 break;
15293 //Set the action script
15294 case IDATASCRIPT:
15295 if(unsigned(ri->idata) >= MAXITEMS)
15296 {
15297 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15298 break;
15299 }
15300 FFScript::deallocateAllScriptOwned(ScriptType::Item, ri->idata);
15301 itemsbuf[ri->idata].script=vbound(value/10000,0,255);
15302 break;
15303 case IDATASPRSCRIPT:
15304 if(unsigned(ri->idata) >= MAXITEMS)
15305 {
15306 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15307 break;
15308 }
15309 itemsbuf[ri->idata].sprite_script=vbound(value/10000,0,255);
15310 break;
15311
15312
15313 //Attributes[10]
15314 case IDATAATTRIB:
15315 case IDATAATTRIB_L:
15316 {
15317 13 int val = value/((arg==IDATAATTRIB_L)?1:10000);
15318
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 if(unsigned(ri->idata) >= MAXITEMS)
15319 {
15320 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15321 break;
15322 }
15323 13 int32_t index = vbound(ri->d[rINDEX]/10000,0,9);
15324
1/11
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
13 switch(index)
15325 {
15326 case 0:
15327 13 itemsbuf[ri->idata].misc1=val;
15328 13 break;
15329 case 1:
15330 itemsbuf[ri->idata].misc2=val; break;
15331 case 2:
15332 itemsbuf[ri->idata].misc3=val; break;
15333 case 3:
15334 itemsbuf[ri->idata].misc4=val; break;
15335 case 4:
15336 itemsbuf[ri->idata].misc5=val; break;
15337 case 5:
15338 itemsbuf[ri->idata].misc6=val; break;
15339 case 6:
15340 itemsbuf[ri->idata].misc7=val; break;
15341 case 7:
15342 itemsbuf[ri->idata].misc8=val; break;
15343 case 8:
15344 itemsbuf[ri->idata].misc9=val; break;
15345 case 9:
15346 itemsbuf[ri->idata].misc10=val; break;
15347
15348 default:
15349 break;
15350 }
15351
15352 13 break;
15353 }
15354 //SpriteSprites[10]
15355 case IDATASPRITE:
15356 {
15357 if(unsigned(ri->idata) >= MAXITEMS)
15358 {
15359 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15360 break;
15361 }
15362 int32_t index = ri->d[rINDEX]/10000;
15363 byte val = vbound(value/10000, 0, 255);
15364 switch(index)
15365 {
15366 case 0:
15367 itemsbuf[ri->idata].wpn = val; break;
15368 case 1:
15369 itemsbuf[ri->idata].wpn2 = val; break;
15370 case 2:
15371 itemsbuf[ri->idata].wpn3 = val; break;
15372 case 3:
15373 itemsbuf[ri->idata].wpn4 = val; break;
15374 case 4:
15375 itemsbuf[ri->idata].wpn5 = val; break;
15376 case 5:
15377 itemsbuf[ri->idata].wpn6 = val; break;
15378 case 6:
15379 itemsbuf[ri->idata].wpn7 = val; break;
15380 case 7:
15381 itemsbuf[ri->idata].wpn8 = val; break;
15382 case 8:
15383 itemsbuf[ri->idata].wpn9 = val; break;
15384 case 9:
15385 itemsbuf[ri->idata].wpn10 = val; break;
15386 default:
15387 scripting_log_error_with_context("Invalid index: {}", index);
15388 break;
15389 }
15390 break;
15391 }
15392 case IDATABURNINGSPR:
15393 {
15394 if(unsigned(ri->idata) >= MAXITEMS)
15395 {
15396 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15397 break;
15398 }
15399 int32_t index = ri->d[rINDEX]/10000;
15400 if(index < 0 || index >= WPNSPR_MAX)
15401 {
15402 scripting_log_error_with_context("Invalid index: {}", index);
15403 break;
15404 }
15405 itemsbuf[ri->idata].burnsprs[index] = vbound(value/10000, 0, 255);
15406 break;
15407 }
15408 case IDATABURNINGLIGHTRAD:
15409 {
15410 if(unsigned(ri->idata) >= MAXITEMS)
15411 {
15412 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15413 break;
15414 }
15415 int32_t index = ri->d[rINDEX]/10000;
15416 if(index < 0 || index >= WPNSPR_MAX)
15417 {
15418 scripting_log_error_with_context("Invalid index: {}", index);
15419 break;
15420 }
15421 itemsbuf[ri->idata].light_rads[index] = vbound(value/10000, 0, 255);
15422 break;
15423 }
15424 //Hero tile modifier.
15425 case IDATALTM:
15426 {
15427 if(unsigned(ri->idata) >= MAXITEMS)
15428 {
15429 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15430 break;
15431 }
15432 auto new_value = value/10000;
15433 if (new_value != itemsbuf[ri->idata].ltm)
15434 cache_tile_mod_clear();
15435 itemsbuf[ri->idata].ltm = new_value;
15436 break;
15437 }
15438 //Pickup script
15439 case IDATAPSCRIPT:
15440 {
15441
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2760 times.
2760 if(unsigned(ri->idata) >= MAXITEMS)
15442 {
15443 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15444 break;
15445 }
15446 //Need to get collect script ref, not standard idata ref!
15447
1/2
✓ Branch 0 taken 2760 times.
✗ Branch 1 not taken.
2760 const int32_t new_ref = ri->idata!=0 ? -(ri->idata) : COLLECT_SCRIPT_ITEM_ZERO;
15448 2760 FFScript::deallocateAllScriptOwned(ScriptType::Item,new_ref);
15449 2760 itemsbuf[ri->idata].collect_script=vbound(value/10000, 0, 255);
15450 2760 break;
15451 }
15452 //pickup string
15453 case IDATAPSTRING:
15454 if(unsigned(ri->idata) >= MAXITEMS)
15455 {
15456 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15457 break;
15458 }
15459 itemsbuf[ri->idata].pstring=vbound(value/10000, 1, 255);
15460 break;
15461 case IDATAPFLAGS:
15462 if(unsigned(ri->idata) >= MAXITEMS)
15463 {
15464 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15465 break;
15466 }
15467 itemsbuf[ri->idata].pickup_string_flags=vbound(value/10000, 0, 214748);
15468 break;
15469 //magic cost
15470 case IDATAMAGCOST:
15471 if(unsigned(ri->idata) >= MAXITEMS)
15472 {
15473 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15474 break;
15475 }
15476 itemsbuf[ri->idata].cost_amount[0]=vbound(value/10000,32767,-32768);
15477 break;
15478 case IDATACOST2:
15479 if(unsigned(ri->idata) >= MAXITEMS)
15480 {
15481 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15482 break;
15483 }
15484 itemsbuf[ri->idata].cost_amount[1]=vbound(value/10000,32767,-32768);
15485 break;
15486 //cost counter ref
15487 case IDATACOSTCOUNTER:
15488 if(unsigned(ri->idata) >= MAXITEMS)
15489 {
15490 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15491 break;
15492 }
15493 itemsbuf[ri->idata].cost_counter[0]=(vbound(value/10000,-1,32));
15494 break;
15495 case IDATACOSTCOUNTER2:
15496 if(unsigned(ri->idata) >= MAXITEMS)
15497 {
15498 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15499 break;
15500 }
15501 itemsbuf[ri->idata].cost_counter[1]=(vbound(value/10000,-1,32));
15502 break;
15503 //min hearts to pick up
15504 case IDATAMINHEARTS:
15505 if(unsigned(ri->idata) >= MAXITEMS)
15506 {
15507 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15508 break;
15509 }
15510 itemsbuf[ri->idata].pickup_hearts=vbound(value/10000, 0, 214748);
15511 break;
15512 //item tile
15513 case IDATATILE:
15514
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 94 times.
94 if(unsigned(ri->idata) >= MAXITEMS)
15515 {
15516 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15517 break;
15518 }
15519 94 itemsbuf[ri->idata].tile=vbound(value/10000, 0, NEWMAXTILES-1);
15520 94 break;
15521 //flash
15522 case IDATAMISC:
15523 if(unsigned(ri->idata) >= MAXITEMS)
15524 {
15525 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15526 break;
15527 }
15528 itemsbuf[ri->idata].misc_flags=value/10000;
15529 break;
15530 //cset
15531 case IDATACSET:
15532
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 if(unsigned(ri->idata) >= MAXITEMS)
15533 {
15534 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15535 break;
15536 }
15537
15538 13 itemsbuf[ri->idata].csets = (itemsbuf[ri->idata].csets & 0xF0) | vbound(value/10000,0,15);
15539
15540 // If we find quests that broke, use this code.
15541 // if (QHeader.compareVer(2, 55, 9) >= 0)
15542 // itemsbuf[ri->idata].csets = (itemsbuf[ri->idata].csets & 0xF0) | vbound(value/10000,0,15);
15543 // else
15544 // itemsbuf[ri->idata].csets = vbound(value/10000,0,13);
15545 13 break;
15546
15547 case IDATAFLASHCSET:
15548 if(unsigned(ri->idata) >= MAXITEMS)
15549 {
15550 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15551 break;
15552 }
15553
15554 itemsbuf[ri->idata].csets = (itemsbuf[ri->idata].csets & 0xF) | (vbound(value/10000,0,15)<<4);
15555 break;
15556 /*
15557 case IDATAFRAME:
15558 itemsbuf[ri->idata].frame=value/10000;
15559 break;
15560 */
15561 //A.Frames
15562 case IDATAFRAMES:
15563 if(unsigned(ri->idata) >= MAXITEMS)
15564 {
15565 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15566 break;
15567 }
15568 (itemsbuf[ri->idata].frames)=vbound(value/10000, 0, 214748);
15569 break;
15570 //A.speed
15571 case IDATAASPEED:
15572 if(unsigned(ri->idata) >= MAXITEMS)
15573 {
15574 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15575 break;
15576 }
15577 itemsbuf[ri->idata].speed=vbound(value/10000, 0, 214748);
15578 break;
15579 //Anim delay
15580 case IDATADELAY:
15581 if(unsigned(ri->idata) >= MAXITEMS)
15582 {
15583 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15584 break;
15585 }
15586 itemsbuf[ri->idata].delay=vbound(value/10000, 0, 214748);
15587 break;
15588
15589 //not one of mine.
15590 case IDATAINITDD:
15591 {
15592 int32_t a = ri->d[rINDEX] / 10000;
15593 if(unsigned(ri->idata) >= MAXITEMS)
15594 {
15595 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
15596 break;
15597 }
15598
15599 if(BC::checkBounds(a, 0, 7) == SH::_NoError)
15600 itemsbuf[ri->idata].initiald[a] = value;
15601 }
15602 break;
15603
15604 ///----------------------------------------------------------------------------------------------------//
15605 //LWeapon Variables
15606
15607 case LWPNSCALE:
15608 if ( get_qr(qr_OLDSPRITEDRAWS) )
15609 {
15610 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
15611 break;
15612 }
15613 if(0!=(s=checkLWpn(ri->lwpn)))
15614 ((weapon*)s)->scale=(zfix)(value/100.0);
15615
15616 break;
15617
15618 case LWPNX:
15619
2/2
✓ Branch 0 taken 6717 times.
✓ Branch 1 taken 207340 times.
214057 if(0!=(s=checkLWpn(ri->lwpn)))
15620
2/2
✓ Branch 0 taken 67473 times.
✓ Branch 1 taken 139867 times.
207340 ((weapon*)s)->x=get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000);
15621 214057 break;
15622
15623 case SPRITEMAXLWPN:
15624 {
15625 //No bounds check, as this is a universal function and works from NULL pointers!
15626 1 Lwpns.setMax(vbound((value/10000),1,MAX_LWPN_SPRITES));
15627 1 break;
15628 }
15629
15630 case LWPNY:
15631
2/2
✓ Branch 0 taken 6717 times.
✓ Branch 1 taken 207326 times.
214043 if(0!=(s=checkLWpn(ri->lwpn)))
15632
2/2
✓ Branch 0 taken 67466 times.
✓ Branch 1 taken 139860 times.
207326 ((weapon*)s)->y=get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000);
15633
15634 214043 break;
15635
15636 case LWPNZ:
15637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 971 times.
971 if(0!=(s=checkLWpn(ri->lwpn)))
15638 {
15639
2/2
✓ Branch 0 taken 965 times.
✓ Branch 1 taken 6 times.
971 ((weapon*)s)->z=get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000);
15640
1/2
✓ Branch 0 taken 971 times.
✗ Branch 1 not taken.
971 if(((weapon*)s)->z < 0) ((weapon*)s)->z = 0_zf;
15641 971 }
15642
15643 971 break;
15644
15645 case LWPNJUMP:
15646
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 408 times.
408 if(0!=(s=checkLWpn(ri->lwpn)))
15647 408 ((weapon*)s)->fall=zslongToFix(value)*-100;
15648
15649 408 break;
15650
15651 case LWPNFAKEJUMP:
15652 if(0!=(s=checkLWpn(ri->lwpn)))
15653 ((weapon*)s)->fakefall=zslongToFix(value)*-100;
15654
15655 break;
15656
15657 case LWPNDIR:
15658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71609 times.
71609 if(0!=(s=checkLWpn(ri->lwpn)))
15659 {
15660 71609 ((weapon*)s)->dir=(value/10000);
15661 71609 ((weapon*)s)->doAutoRotate(true);
15662 71609 }
15663
15664 71609 break;
15665
15666 case LWPNSPECIAL:
15667 if(0!=(s=checkLWpn(ri->lwpn)))
15668 ((weapon*)s)->specialinfo=(value/10000);
15669
15670 break;
15671
15672 case LWPNGRAVITY:
15673 if(0!=(s=checkLWpn(ri->lwpn)))
15674 {
15675 if(value)
15676 ((weapon*)s)->moveflags |= move_obeys_grav;
15677 else
15678 ((weapon*)s)->moveflags &= ~move_obeys_grav;
15679 }
15680 break;
15681
15682 case LWPNSTEP:
15683
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9786 times.
9786 if(0!=(s=checkLWpn(ri->lwpn)))
15684 {
15685 // fp math is bad for replay, so always ignore this QR when replay is active.
15686 // TODO: can we just delete this QR? Would it actually break anything? For now,
15687 // just disable for replay and wait for more tests to be played with this QR
15688 // ignored.
15689
3/4
✓ Branch 0 taken 7619 times.
✓ Branch 1 taken 2167 times.
✓ Branch 2 taken 7619 times.
✗ Branch 3 not taken.
9786 if ( get_qr(qr_STEP_IS_FLOAT) || replay_is_active() )
15690 {
15691 9786 ((weapon*)s)->step= zslongToFix(value / 100);
15692 9786 }
15693 else
15694 {
15695 //old, buggy code replication, round two: Go! -Z
15696 //zfix val = zslongToFix(value);
15697 //val.doFloor();
15698 //((weapon*)s)->step = ((val / 100.0).getFloat());
15699
15700 //old, buggy code replication, round THREE: Go! -Z
15701 ((weapon*)s)->step = ((value/10000)/100.0);
15702 }
15703
15704 9786 }
15705
15706 9786 break;
15707
15708 case LWPNANGLE:
15709
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1679 times.
1679 if(0!=(s=checkLWpn(ri->lwpn)))
15710 {
15711 1679 ((weapon*)s)->angle=(double)(value/10000.0);
15712 1679 ((weapon*)(s))->doAutoRotate();
15713 1679 }
15714
15715 1679 break;
15716
15717 case LWPNDEGANGLE:
15718 if(0!=(s=checkLWpn(ri->lwpn)))
15719 {
15720 double rangle = (value / 10000.0) * (PI / 180.0);
15721 ((weapon*)s)->angle=(double)(rangle);
15722 ((weapon*)(s))->doAutoRotate();
15723 }
15724
15725 break;
15726
15727 case LWPNVX:
15728
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
15729 {
15730 double vy;
15731 6 double vx = (value / 10000.0);
15732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (((weapon*)(s))->angular)
15733 vy = zc::math::Sin(((weapon*)s)->angle)*((weapon*)s)->step;
15734 else
15735 {
15736
5/7
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 2 times.
6 switch(NORMAL_DIR(((weapon*)(s))->dir))
15737 {
15738 case l_up:
15739 case r_up:
15740 case up:
15741 2 vy = -1.0*((weapon*)s)->step;
15742 2 break;
15743 case l_down:
15744 case r_down:
15745 case down:
15746 2 vy = ((weapon*)s)->step;
15747 2 break;
15748
15749 default:
15750 2 vy = 0;
15751 2 break;
15752 }
15753 }
15754 6 ((weapon*)s)->angular = true;
15755 6 ((weapon*)s)->angle=atan2(vy, vx);
15756 6 ((weapon*)s)->step=FFCore.Distance(0, 0, vx, vy)/10000.0;
15757 6 ((weapon*)(s))->doAutoRotate();
15758 6 }
15759
15760 6 break;
15761
15762 case LWPNVY:
15763
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
15764 {
15765 double vx;
15766 6 double vy = (value / 10000.0);
15767
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (((weapon*)(s))->angular)
15768 6 vx = zc::math::Cos(((weapon*)s)->angle)*((weapon*)s)->step;
15769 else
15770 {
15771 switch(NORMAL_DIR(((weapon*)(s))->dir))
15772 {
15773 case l_up:
15774 case l_down:
15775 case left:
15776 vx = -1.0*((weapon*)s)->step;
15777 break;
15778 case r_down:
15779 case r_up:
15780 case right:
15781 vx = ((weapon*)s)->step;
15782 break;
15783
15784 default:
15785 vx = 0;
15786 break;
15787 }
15788 }
15789 6 ((weapon*)s)->angular = true;
15790 6 ((weapon*)s)->angle=atan2(vy, vx);
15791 6 ((weapon*)s)->step=FFCore.Distance(0, 0, vx, vy)/10000.0;
15792 6 ((weapon*)(s))->doAutoRotate();
15793 6 }
15794
15795 6 break;
15796
15797 case LWPNANGULAR:
15798
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1181 times.
1181 if(0!=(s=checkLWpn(ri->lwpn)))
15799 {
15800 1181 ((weapon*)s)->angular=(value!=0);
15801 1181 ((weapon*)(s))->doAutoRotate(false, true);
15802 1181 }
15803
15804 1181 break;
15805
15806 case LWPNAUTOROTATE:
15807 if(0!=(s=checkLWpn(ri->lwpn)))
15808 {
15809 ((weapon*)s)->autorotate=(value!=0);
15810 ((weapon*)(s))->doAutoRotate(false, true);
15811 }
15812
15813 break;
15814
15815 case LWPNBEHIND:
15816
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1131 times.
1131 if(0!=(s=checkLWpn(ri->lwpn)))
15817 1131 ((weapon*)s)->behind=(value!=0);
15818
15819 1131 break;
15820
15821 case LWPNDRAWTYPE:
15822
1/2
✓ Branch 0 taken 476 times.
✗ Branch 1 not taken.
476 if(0!=(s=checkLWpn(ri->lwpn)))
15823 476 ((weapon*)s)->drawstyle=(value/10000);
15824
15825 476 break;
15826
15827 case LWPNPOWER:
15828
1/2
✓ Branch 0 taken 76041 times.
✗ Branch 1 not taken.
76041 if(0!=(s=checkLWpn(ri->lwpn)))
15829 76041 ((weapon*)s)->power=(value/10000);
15830
15831 76041 break;
15832 /*
15833 case LWPNRANGE:
15834 if(0!=(s=checkLWpn(ri->lwpn)))
15835 ((weapon*)s)->scriptrange=vbound((value/10000),0,512); //Allow it to move off-screen. -Z
15836 break;
15837 */
15838 case LWPNDEAD:
15839
2/2
✓ Branch 0 taken 6717 times.
✓ Branch 1 taken 147078 times.
153795 if(0!=(s=checkLWpn(ri->lwpn)))
15840 {
15841 147078 auto dead = value/10000;
15842 147078 ((weapon*)s)->dead=dead;
15843
2/2
✓ Branch 0 taken 74907 times.
✓ Branch 1 taken 72171 times.
147078 if(dead != 0) ((weapon*)s)->weapon_dying_frame = false;
15844 147078 }
15845 153795 break;
15846
15847 case LWPNID:
15848 if(0!=(s=checkLWpn(ri->lwpn)))
15849 ((weapon*)s)->id=(value/10000);
15850
15851 break;
15852
15853 case LWPNTILE:
15854
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2464 times.
2464 if(0!=(s=checkLWpn(ri->lwpn)))
15855 2464 ((weapon*)s)->tile=(value/10000);
15856
15857 2464 break;
15858
15859 case LWPNSCRIPTTILE:
15860
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3263 times.
3263 if(0!=(s=checkLWpn(ri->lwpn)))
15861 3263 ((weapon*)s)->scripttile=vbound((value/10000),-1,NEWMAXTILES-1);
15862
15863 3263 break;
15864
15865 case LWPNSCRIPTFLIP:
15866 if(0!=(s=checkLWpn(ri->lwpn)))
15867 ((weapon*)s)->scriptflip=vbound((value/10000),-1,127);
15868
15869 break;
15870
15871 case LWPNCSET:
15872
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26540 times.
26540 if(0!=(s=checkLWpn(ri->lwpn)))
15873 26540 ((weapon*)s)->cs=(value/10000)&15;
15874
15875 26540 break;
15876
15877 case LWPNFLASHCSET:
15878
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
15879 6 (((weapon*)s)->o_cset)|=(value/10000)<<4;
15880
15881 6 break;
15882
15883 case LWPNFRAMES:
15884
1/2
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
429 if(0!=(s=checkLWpn(ri->lwpn)))
15885 429 ((weapon*)s)->frames=(value/10000);
15886
15887 429 break;
15888
15889 case LWPNFRAME:
15890
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
15891 6 ((weapon*)s)->aframe=(value/10000);
15892
15893 6 break;
15894
15895 case LWPNASPEED:
15896
1/2
✓ Branch 0 taken 527 times.
✗ Branch 1 not taken.
527 if(0!=(s=checkLWpn(ri->lwpn)))
15897 527 ((weapon*)s)->o_speed=(value/10000);
15898
15899 527 break;
15900
15901 case LWPNFLASH:
15902
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
15903 6 ((weapon*)s)->flash=(value/10000);
15904
15905 6 break;
15906
15907 case LWPNFLIP:
15908
1/2
✓ Branch 0 taken 885 times.
✗ Branch 1 not taken.
885 if(0!=(s=checkLWpn(ri->lwpn)))
15909 885 ((weapon*)s)->flip=(value/10000);
15910
15911 885 break;
15912
15913 case LWPNROTATION:
15914
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4922 times.
4922 if ( get_qr(qr_OLDSPRITEDRAWS) )
15915 {
15916 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
15917 break;
15918 }
15919
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4922 times.
4922 if(0!=(s=checkLWpn(ri->lwpn)))
15920 4922 ((weapon*)s)->rotation=(value/10000);
15921
15922 4922 break;
15923
15924 case LWPNEXTEND:
15925
1/2
✓ Branch 0 taken 839 times.
✗ Branch 1 not taken.
839 if(0!=(s=checkLWpn(ri->lwpn)))
15926 839 ((weapon*)s)->extend=(value/10000);
15927
15928 839 break;
15929
15930 case LWPNOTILE:
15931
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2345 times.
2345 if(0!=(s=checkLWpn(ri->lwpn)))
15932 {
15933 2345 ((weapon*)s)->o_tile=(value/10000);
15934 2345 ((weapon*)s)->ref_o_tile=(value/10000);
15935 //((weapon*)s)->script_wrote_otile=1; //Removing this as of 26th October, 2019 -Z
15936 //if at some future point we WANT writing ->Tile to also overwrite ->OriginalTile,
15937 //then either the user will need to manually write tile, or we can add a QR and
15938 // write ->tile here. 'script_wrote_otile' is out.
15939 2345 }
15940 2345 break;
15941
15942 case LWPNOCSET:
15943
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
15944 6 (((weapon*)s)->o_cset)|=(value/10000)&15;
15945
15946 6 break;
15947
15948 case LWPNHXOFS:
15949
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71310 times.
71310 if(0!=(s=checkLWpn(ri->lwpn)))
15950 71310 (((weapon*)s)->hxofs)=(value/10000);
15951
15952 71310 break;
15953
15954 case LWPNHYOFS:
15955
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71308 times.
71308 if(0!=(s=checkLWpn(ri->lwpn)))
15956 71308 (((weapon*)s)->hyofs)=(value/10000);
15957
15958 71308 break;
15959
15960 case LWPNXOFS:
15961
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1768 times.
1768 if(0!=(s=checkLWpn(ri->lwpn)))
15962 1768 (((weapon*)s)->xofs)=(zfix)(value/10000);
15963
15964 1768 break;
15965
15966 case LWPNYOFS:
15967
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70954 times.
70954 if(0!=(s=checkLWpn(ri->lwpn)))
15968
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70954 times.
70954 (((weapon*)s)->yofs)=(zfix)(value/10000)+(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset);
15969
15970 70954 break;
15971
15972 case LWPNSHADOWXOFS:
15973 if(0!=(s=checkLWpn(ri->lwpn)))
15974 (((weapon*)s)->shadowxofs)=(zfix)(value/10000);
15975
15976 break;
15977
15978 case LWPNSHADOWYOFS:
15979 if(0!=(s=checkLWpn(ri->lwpn)))
15980 (((weapon*)s)->shadowyofs)=(zfix)(value/10000);
15981
15982 break;
15983
15984 case LWPNTOTALDYOFFS:
15985 break; //READ-ONLY
15986
15987 case LWPNZOFS:
15988
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
15989 6 (((weapon*)s)->zofs)=(zfix)(value/10000);
15990
15991 6 break;
15992
15993 case LWPNHXSZ:
15994
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72525 times.
72525 if(0!=(s=checkLWpn(ri->lwpn)))
15995 72525 (((weapon*)s)->hit_width)=(value/10000);
15996
15997 72525 break;
15998
15999 case LWPNHYSZ:
16000
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72542 times.
72542 if(0!=(s=checkLWpn(ri->lwpn)))
16001 72542 (((weapon*)s)->hit_height)=(value/10000);
16002
16003 72542 break;
16004
16005 case LWPNHZSZ:
16006
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
16007 6 (((weapon*)s)->hzsz)=(value/10000);
16008
16009 6 break;
16010
16011 case LWPNTXSZ:
16012
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 833 times.
833 if(0!=(s=checkLWpn(ri->lwpn)))
16013 833 (((weapon*)s)->txsz)=vbound((value/10000),1,20);
16014
16015 833 break;
16016
16017 case LWPNTYSZ:
16018
1/2
✓ Branch 0 taken 833 times.
✗ Branch 1 not taken.
833 if(0!=(s=checkLWpn(ri->lwpn)))
16019 833 (((weapon*)s)->tysz)=vbound((value/10000),1,20);
16020
16021 833 break;
16022
16023 case LWPNMISCD:
16024
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 534237 times.
534237 if(0!=(s=checkLWpn(ri->lwpn)))
16025 {
16026 534237 int32_t a = vbound(ri->d[rINDEX]/10000,0,31);
16027 534237 (((weapon*)(s))->miscellaneous[a])=value;
16028 534237 }
16029
16030 534237 break;
16031
16032 case LWPNCOLLDET:
16033
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18928 times.
18928 if(0!=(s=checkLWpn(ri->lwpn)))
16034 18928 (((weapon*)(s))->scriptcoldet) = value;
16035
16036 18928 break;
16037
16038 case LWPNENGINEANIMATE:
16039 if(0!=(s=checkLWpn(ri->lwpn)))
16040 (((weapon*)(s))->do_animation)=value;
16041
16042 break;
16043
16044 case LWPNPARENT:
16045 {
16046 //int32_t pitm = (vbound(value/10000,1,(MAXITEMS-1)));
16047
16048
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if(0!=(s=checkLWpn(ri->lwpn)))
16049 42 (((weapon*)(s))->parentitem)=(vbound(value/10000,-1,(MAXITEMS-1)));
16050 42 break;
16051 }
16052
16053 case LWPNLEVEL:
16054
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(0!=(s=checkLWpn(ri->lwpn)))
16055 12 (((weapon*)(s))->type)=value/10000;
16056
16057 12 break;
16058
16059 case LWPNSCRIPT:
16060
1/2
✓ Branch 0 taken 62002 times.
✗ Branch 1 not taken.
62002 if(0!=(s=checkLWpn(ri->lwpn)))
16061 {
16062 62002 (((weapon*)(s))->weaponscript)=vbound(value/10000,0,NUMSCRIPTWEAPONS-1);
16063
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62002 times.
62002 if ( get_qr(qr_CLEARINITDONSCRIPTCHANGE))
16064 {
16065
2/2
✓ Branch 0 taken 496016 times.
✓ Branch 1 taken 62002 times.
558018 for(int32_t q=0; q<8; q++)
16066 496016 (((weapon*)(s))->weap_initd[q]) = 0;
16067 62002 }
16068 62002 on_reassign_script_engine_data(ScriptType::Lwpn, ri->lwpn);
16069 62002 }
16070 62002 break;
16071
16072 case LWPNUSEWEAPON:
16073
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1130 times.
1130 if(0!=(s=checkLWpn(ri->lwpn)))
16074 1130 (((weapon*)(s))->useweapon)=vbound(value/10000,0,255);
16075
16076 1130 break;
16077
16078 case LWPNUSEDEFENCE:
16079 if(0!=(s=checkLWpn(ri->lwpn)))
16080 (((weapon*)(s))->usedefence)=vbound(value/10000,0,255);
16081
16082 break;
16083
16084 case LWPNINITD:
16085 {
16086 1210 int32_t a = vbound((ri->d[rINDEX] / 10000),0,7);
16087
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1210 times.
1210 if(0!=(s=checkLWpn(ri->lwpn)))
16088 {
16089 1210 (((weapon*)(s))->weap_initd[a])=value;
16090 1210 }
16091 1210 break;
16092 }
16093 case LWPNFALLCLK:
16094 if(0!=(s=checkLWpn(ri->lwpn)))
16095 {
16096 if(((weapon*)(s))->fallclk != 0 && value == 0)
16097 {
16098 ((weapon*)(s))->cs = ((weapon*)(s))->o_cset;
16099 ((weapon*)(s))->tile = ((weapon*)(s))->o_tile;
16100 }
16101 else if(((weapon*)(s))->fallclk == 0 && value != 0) ((weapon*)(s))->o_cset = ((weapon*)(s))->cs;
16102 ((weapon*)(s))->fallclk = vbound(value/10000,0,70);
16103 }
16104 break;
16105 case LWPNFALLCMB:
16106 if(0!=(s=checkLWpn(ri->lwpn)))
16107 {
16108 ((weapon*)(s))->fallCombo = vbound(value/10000,0,MAXCOMBOS-1);
16109 }
16110 break;
16111 case LWPNDROWNCLK:
16112 if(0!=(s=checkLWpn(ri->lwpn)))
16113 {
16114 if(((weapon*)(s))->drownclk != 0 && value == 0)
16115 {
16116 ((weapon*)(s))->cs = ((weapon*)(s))->o_cset;
16117 ((weapon*)(s))->tile = ((weapon*)(s))->o_tile;
16118 }
16119 else if(((weapon*)(s))->drownclk == 0 && value != 0) ((weapon*)(s))->o_cset = ((weapon*)(s))->cs;
16120 ((weapon*)(s))->drownclk = vbound(value/10000,0,70);
16121 }
16122 break;
16123 case LWPNDROWNCMB:
16124 if(0!=(s=checkLWpn(ri->lwpn)))
16125 {
16126 ((weapon*)(s))->drownCombo = vbound(value/10000,0,MAXCOMBOS-1);
16127 }
16128 break;
16129 case LWPNFAKEZ:
16130 if(0!=(s=checkLWpn(ri->lwpn)))
16131 {
16132 ((weapon*)s)->fakez=get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000);
16133 if(((weapon*)s)->fakez < 0) ((weapon*)s)->fakez = 0_zf;
16134 }
16135
16136 break;
16137
16138 case LWPNMOVEFLAGS:
16139 {
16140
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1042 times.
1042 if(0!=(s=checkLWpn(ri->lwpn)))
16141 {
16142 1042 int32_t indx = ri->d[rINDEX]/10000;
16143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1042 times.
1042 if(BC::checkIndex(indx, 0, 10) == SH::_NoError)
16144 {
16145 //All bits, in order, of a single byte; just use bitwise
16146 1042 move_flags bit = (move_flags)(1<<indx);
16147
2/2
✓ Branch 0 taken 259 times.
✓ Branch 1 taken 783 times.
1042 if(value)
16148 259 ((weapon*)(s))->moveflags |= bit;
16149 else
16150 783 ((weapon*)(s))->moveflags &= ~bit;
16151 1042 }
16152 1042 }
16153 1042 break;
16154 }
16155 case LWPNFLAGS:
16156 {
16157 if(0!=(s=checkLWpn(ri->lwpn)))
16158 {
16159 int32_t indx = ri->d[rINDEX]/10000;
16160 if(BC::checkIndex(indx, 0, WFLAG_MAX-1) == SH::_NoError)
16161 {
16162 //All bits, in order, of a single byte; just use bitwise
16163 weapon_flags bit = weapon_flags(1<<indx);
16164 if(value)
16165 ((weapon*)(s))->misc_wflags |= bit;
16166 else
16167 ((weapon*)(s))->misc_wflags &= ~bit;
16168 }
16169 }
16170 break;
16171 }
16172 case LWPNSPRITES:
16173 {
16174 if(0!=(s=checkLWpn(ri->lwpn)))
16175 {
16176 int32_t indx = ri->d[rINDEX]/10000;
16177 if(BC::checkIndex(indx, 0, WPNSPR_MAX-1) == SH::_NoError)
16178 ((weapon*)(s))->misc_wsprites[indx] = vbound(value/10000,0,255);
16179 }
16180 break;
16181 }
16182 case LWPNBURNLIGHTRADIUS:
16183 {
16184 if(0!=(s=checkLWpn(ri->lwpn)))
16185 {
16186 int32_t indx = ri->d[rINDEX]/10000;
16187 if(BC::checkIndex(indx, 0, WPNSPR_MAX-1) == SH::_NoError)
16188 ((weapon*)(s))->light_rads[indx] = vbound(value/10000,0,255);
16189 }
16190 break;
16191 }
16192
16193 case LWPNGLOWRAD:
16194
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 527 times.
527 if(0!=(s=checkLWpn(ri->lwpn)))
16195 {
16196 527 ((weapon*)(s))->glowRad = vbound(value/10000,0,255);
16197 527 }
16198 527 break;
16199
16200 case LWPNGLOWSHP:
16201 if(0!=(s=checkLWpn(ri->lwpn)))
16202 {
16203 ((weapon*)(s))->glowShape = vbound(value/10000,0,255);
16204 }
16205 break;
16206
16207 case LWPNUNBL:
16208 if(0!=(s=checkLWpn(ri->lwpn)))
16209 {
16210 ((weapon*)(s))->unblockable = (value/10000)&WPNUNB_ALL;
16211 }
16212 break;
16213
16214 case LWPNSHADOWSPR:
16215 if(0!=(s=checkLWpn(ri->lwpn)))
16216 {
16217 ((weapon*)(s))->spr_shadow = vbound(value/10000, 0, 255);
16218 }
16219 break;
16220 case LWSWHOOKED:
16221 break; //read-only
16222 case LWPNTIMEOUT:
16223 if(0!=(s=checkLWpn(ri->lwpn)))
16224 {
16225 ((weapon*)(s))->weap_timeout = vbound(value/10000,0,214748);
16226 }
16227 break;
16228 case LWPNDEATHITEM:
16229 if(0!=(s=checkLWpn(ri->lwpn)))
16230 {
16231 ((weapon*)(s))->death_spawnitem = vbound(value/10000,-1,MAXITEMS-1);
16232 }
16233 break;
16234 case LWPNDEATHDROPSET:
16235 if(0!=(s=checkLWpn(ri->lwpn)))
16236 {
16237 ((weapon*)(s))->death_spawndropset = vbound(value/10000,-1,MAXITEMDROPSETS-1);
16238 }
16239 break;
16240 case LWPNDEATHIPICKUP:
16241 if(0!=(s=checkLWpn(ri->lwpn)))
16242 {
16243 ((weapon*)(s))->death_item_pflags = value/10000;
16244 }
16245 break;
16246 case LWPNDEATHSPRITE:
16247 if(0!=(s=checkLWpn(ri->lwpn)))
16248 {
16249 ((weapon*)(s))->death_sprite = vbound(value/10000,-255,MAXWPNS-1);
16250 }
16251 break;
16252 case LWPNDEATHSFX:
16253 if(0!=(s=checkLWpn(ri->lwpn)))
16254 {
16255 ((weapon*)(s))->death_sfx = vbound(value/10000,0,WAV_COUNT);
16256 }
16257 break;
16258 case LWPNLIFTLEVEL:
16259 if(0!=(s=checkLWpn(ri->lwpn)))
16260 {
16261 ((weapon*)(s))->lift_level = vbound(value/10000,0,255);
16262 }
16263 break;
16264 case LWPNLIFTTIME:
16265 if(0!=(s=checkLWpn(ri->lwpn)))
16266 {
16267 ((weapon*)(s))->lift_time = vbound(value/10000,0,255);
16268 }
16269 break;
16270 case LWPNLIFTHEIGHT:
16271 if(0!=(s=checkLWpn(ri->lwpn)))
16272 {
16273 ((weapon*)(s))->lift_height = zslongToFix(value);
16274 }
16275 break;
16276
16277 ///----------------------------------------------------------------------------------------------------//
16278 //EWeapon Variables
16279 case EWPNSCALE:
16280 if ( get_qr(qr_OLDSPRITEDRAWS) )
16281 {
16282 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
16283 break;
16284 }
16285 if(0!=(s=checkEWpn(ri->ewpn)))
16286 ((weapon*)s)->scale=(zfix)(value/100.0);
16287
16288 break;
16289
16290 case EWPNX:
16291
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 390183 times.
390183 if(0!=(s=checkEWpn(ri->ewpn)))
16292
2/2
✓ Branch 0 taken 38744 times.
✓ Branch 1 taken 351439 times.
390183 ((weapon*)s)->x = (get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000));
16293
16294 390183 break;
16295
16296 case SPRITEMAXEWPN:
16297 {
16298 //No bounds check, as this is a universal function and works from NULL pointers!
16299 1 Ewpns.setMax(vbound((value/10000),1,MAX_EWPN_SPRITES));
16300 1 break;
16301 }
16302
16303 case EWPNY:
16304
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 390780 times.
390780 if(0!=(s=checkEWpn(ri->ewpn)))
16305
2/2
✓ Branch 0 taken 38610 times.
✓ Branch 1 taken 352170 times.
390780 ((weapon*)s)->y = (get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000));
16306
16307 390780 break;
16308
16309 case EWPNZ:
16310
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57530 times.
57530 if(0!=(s=checkEWpn(ri->ewpn)))
16311 {
16312
2/2
✓ Branch 0 taken 1291 times.
✓ Branch 1 taken 56239 times.
57530 ((weapon*)s)->z=get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000);
16313
2/2
✓ Branch 0 taken 57119 times.
✓ Branch 1 taken 411 times.
57530 if(((weapon*)s)->z < 0) ((weapon*)s)->z = 0_zf;
16314 57530 }
16315
16316 57530 break;
16317
16318 case EWPNJUMP:
16319
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55587 times.
55587 if(0!=(s=checkEWpn(ri->ewpn)))
16320 55587 ((weapon*)s)->fall=zslongToFix(value)*-100;
16321
16322 55587 break;
16323
16324 case EWPNFAKEJUMP:
16325 if(0!=(s=checkEWpn(ri->ewpn)))
16326 ((weapon*)s)->fakefall=zslongToFix(value)*-100;
16327
16328 break;
16329
16330 case EWPNDIR:
16331
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 227256 times.
227256 if(0!=(s=checkEWpn(ri->ewpn)))
16332 {
16333 227256 ((weapon*)s)->dir=(value/10000);
16334 227256 ((weapon*)s)->doAutoRotate(true);
16335 227256 }
16336
16337 227256 break;
16338
16339 case EWPNLEVEL:
16340
1/2
✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
117 if(0!=(s=checkEWpn(ri->ewpn)))
16341 117 ((weapon*)s)->type=(value/10000);
16342
16343 117 break;
16344
16345 case EWPNGRAVITY:
16346 if(0!=(s=checkEWpn(ri->ewpn)))
16347 {
16348 if(value)
16349 ((weapon*)s)->moveflags |= move_obeys_grav;
16350 else
16351 ((weapon*)s)->moveflags &= ~move_obeys_grav;
16352 }
16353 break;
16354
16355 case EWPNSTEP:
16356
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 372485 times.
372485 if(0!=(s=checkEWpn(ri->ewpn)))
16357 {
16358
3/4
✓ Branch 0 taken 350322 times.
✓ Branch 1 taken 22163 times.
✓ Branch 2 taken 350322 times.
✗ Branch 3 not taken.
372485 if ( get_qr(qr_STEP_IS_FLOAT) || replay_is_active() )
16359 {
16360 372485 ((weapon*)s)->step= zslongToFix(value / 100);
16361 372485 }
16362 else
16363 {
16364 //old, buggy code replication, round two: Go! -Z
16365 //zfix val = zslongToFix(value);
16366 //val.doFloor();
16367 //((weapon*)s)->step = ((val / 100.0).getFloat());
16368
16369 //old, buggy code replication, round THREE: Go! -Z
16370 ((weapon*)s)->step = ((value/10000)/100.0);
16371 }
16372 372485 }
16373
16374 372485 break;
16375
16376 case EWPNANGLE:
16377
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 220884 times.
220890 if(0!=(s=checkEWpn(ri->ewpn)))
16378 {
16379 220884 ((weapon*)s)->angle=(double)(value/10000.0);
16380 220884 ((weapon*)(s))->doAutoRotate();
16381 220884 }
16382
16383 220890 break;
16384
16385 case EWPNDEGANGLE:
16386 if(0!=(s=checkEWpn(ri->ewpn)))
16387 {
16388 double rangle = (value / 10000.0) * (PI / 180.0);
16389 ((weapon*)s)->angle=(double)(rangle);
16390 ((weapon*)(s))->doAutoRotate();
16391 }
16392
16393 break;
16394
16395 case EWPNVX:
16396 if(0!=(s=checkEWpn(ri->ewpn)))
16397 {
16398 double vy;
16399 double vx = (value / 10000.0);
16400 if (((weapon*)(s))->angular)
16401 vy = zc::math::Sin(((weapon*)s)->angle)*((weapon*)s)->step;
16402 else
16403 {
16404 switch(NORMAL_DIR(((weapon*)(s))->dir))
16405 {
16406 case l_up:
16407 case r_up:
16408 case up:
16409 vy = -1.0*((weapon*)s)->step;
16410 break;
16411 case l_down:
16412 case r_down:
16413 case down:
16414 vy = ((weapon*)s)->step;
16415 break;
16416
16417 default:
16418 vy = 0;
16419 break;
16420 }
16421 }
16422 ((weapon*)s)->angular = true;
16423 ((weapon*)s)->angle=atan2(vy, vx);
16424 ((weapon*)s)->step=FFCore.Distance(0, 0, vx, vy)/10000;
16425 ((weapon*)(s))->doAutoRotate();
16426 }
16427
16428 break;
16429
16430 case EWPNVY:
16431 if(0!=(s=checkEWpn(ri->ewpn)))
16432 {
16433 double vx;
16434 double vy = (value / 10000.0);
16435 if (((weapon*)(s))->angular)
16436 vx = zc::math::Cos(((weapon*)s)->angle)*((weapon*)s)->step;
16437 else
16438 {
16439 switch(NORMAL_DIR(((weapon*)(s))->dir))
16440 {
16441 case l_up:
16442 case l_down:
16443 case left:
16444 vx = -1.0*((weapon*)s)->step;
16445 break;
16446 case r_down:
16447 case r_up:
16448 case right:
16449 vx = ((weapon*)s)->step;
16450 break;
16451
16452 default:
16453 vx = 0;
16454 break;
16455 }
16456 }
16457 ((weapon*)s)->angular = true;
16458 ((weapon*)s)->angle=atan2(vy, vx);
16459 ((weapon*)s)->step=FFCore.Distance(0, 0, vx, vy)/10000;
16460 ((weapon*)(s))->doAutoRotate();
16461 }
16462
16463 break;
16464
16465 case EWPNANGULAR:
16466
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 208988 times.
208988 if(0!=(s=checkEWpn(ri->ewpn)))
16467 {
16468 208988 ((weapon*)s)->angular=(value!=0);
16469 208988 ((weapon*)(s))->doAutoRotate(false, true);
16470 208988 }
16471
16472 208988 break;
16473
16474 case EWPNAUTOROTATE:
16475 if(0!=(s=checkEWpn(ri->ewpn)))
16476 {
16477 ((weapon*)s)->autorotate=(value!=0);
16478 ((weapon*)(s))->doAutoRotate(false, true);
16479 }
16480
16481 break;
16482
16483 case EWPNBEHIND:
16484
1/2
✓ Branch 0 taken 5420 times.
✗ Branch 1 not taken.
5420 if(0!=(s=checkEWpn(ri->ewpn)))
16485 5420 ((weapon*)s)->behind=(value!=0);
16486
16487 5420 break;
16488
16489 case EWPNDRAWTYPE:
16490
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12175 times.
12175 if(0!=(s=checkEWpn(ri->ewpn)))
16491 12175 ((weapon*)s)->drawstyle=(value/10000);
16492
16493 12175 break;
16494
16495 case EWPNPOWER:
16496
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 210232 times.
210232 if(0!=(s=checkEWpn(ri->ewpn)))
16497 210232 ((weapon*)s)->power=(value/10000);
16498
16499 210232 break;
16500
16501 case EWPNDEAD:
16502
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 114186 times.
114186 if(0!=(s=checkEWpn(ri->ewpn)))
16503 {
16504 114186 auto dead = value/10000;
16505 114186 ((weapon*)s)->dead=dead;
16506
2/2
✓ Branch 0 taken 28037 times.
✓ Branch 1 taken 86149 times.
114186 if(dead != 0) ((weapon*)s)->weapon_dying_frame = false;
16507 114186 }
16508
16509 114186 break;
16510
16511 case EWPNID:
16512 if(0!=(s=checkEWpn(ri->ewpn)))
16513 ((weapon*)s)->id=(value/10000);
16514
16515 break;
16516
16517 case EWPNTILE:
16518
1/2
✓ Branch 0 taken 74446 times.
✗ Branch 1 not taken.
74446 if(0!=(s=checkEWpn(ri->ewpn)))
16519 74446 ((weapon*)s)->tile=(value/10000);
16520
16521 74446 break;
16522
16523 case EWPNSCRIPTTILE:
16524
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 178 times.
178 if(0!=(s=checkEWpn(ri->ewpn)))
16525 178 ((weapon*)s)->scripttile=vbound((value/10000),-1, NEWMAXTILES-1);
16526
16527 178 break;
16528
16529 case EWPNSCRIPTFLIP:
16530 if(0!=(s=checkEWpn(ri->ewpn)))
16531 ((weapon*)s)->scriptflip=vbound((value/10000),-1, 127);
16532
16533 break;
16534
16535 case EWPNCSET:
16536
1/2
✓ Branch 0 taken 35337 times.
✗ Branch 1 not taken.
35337 if(0!=(s=checkEWpn(ri->ewpn)))
16537 35337 ((weapon*)s)->cs=(value/10000)&15;
16538
16539 35337 break;
16540
16541 case EWPNFLASHCSET:
16542 if(0!=(s=checkEWpn(ri->ewpn)))
16543 (((weapon*)s)->o_cset)|=(value/10000)<<4;
16544
16545 break;
16546
16547 case EWPNFRAMES:
16548
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if(0!=(s=checkEWpn(ri->ewpn)))
16549 41 ((weapon*)s)->frames=(value/10000);
16550
16551 41 break;
16552
16553 case EWPNFRAME:
16554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1039 times.
1039 if(0!=(s=checkEWpn(ri->ewpn)))
16555 1039 ((weapon*)s)->aframe=(value/10000);
16556
16557 1039 break;
16558
16559 case EWPNASPEED:
16560
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if(0!=(s=checkEWpn(ri->ewpn)))
16561 41 ((weapon*)s)->o_speed=(value/10000);
16562
16563 41 break;
16564
16565 case EWPNFLASH:
16566
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 549 times.
549 if(0!=(s=checkEWpn(ri->ewpn)))
16567 549 ((weapon*)s)->flash=(value/10000);
16568
16569 549 break;
16570
16571 case EWPNFLIP:
16572
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 78832 times.
78832 if(0!=(s=checkEWpn(ri->ewpn)))
16573 78832 ((weapon*)s)->flip=(value/10000);
16574
16575 78832 break;
16576
16577 case EWPNROTATION:
16578
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1104 times.
1104 if ( get_qr(qr_OLDSPRITEDRAWS) )
16579 {
16580 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'");
16581 break;
16582 }
16583
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1104 times.
1104 if(0!=(s=checkEWpn(ri->ewpn)))
16584 1104 ((weapon*)s)->rotation=(value/10000);
16585
16586 1104 break;
16587
16588 case EWPNEXTEND:
16589
1/2
✓ Branch 0 taken 156969 times.
✗ Branch 1 not taken.
156969 if(0!=(s=checkEWpn(ri->ewpn)))
16590 156969 ((weapon*)s)->extend=(value/10000);
16591
16592 156969 break;
16593
16594 case EWPNOTILE:
16595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4552 times.
4552 if(0!=(s=checkEWpn(ri->ewpn)))
16596 {
16597 4552 ((weapon*)s)->o_tile=(value/10000);
16598 4552 ((weapon*)s)->ref_o_tile=(value/10000);
16599 4552 }
16600
16601 4552 break;
16602
16603 case EWPNOCSET:
16604 if(0!=(s=checkEWpn(ri->ewpn)))
16605 (((weapon*)s)->o_cset)|=(value/10000)&15;
16606
16607 break;
16608
16609 case EWPNHXOFS:
16610
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 194229 times.
194229 if(0!=(s=checkEWpn(ri->ewpn)))
16611 194229 (((weapon*)s)->hxofs)=(value/10000);
16612
16613 194229 break;
16614
16615 case EWPNHYOFS:
16616
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 193736 times.
193736 if(0!=(s=checkEWpn(ri->ewpn)))
16617 193736 (((weapon*)s)->hyofs)=(value/10000);
16618
16619 193736 break;
16620
16621 case EWPNXOFS:
16622
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 84990 times.
84994 if(0!=(s=checkEWpn(ri->ewpn)))
16623 84990 (((weapon*)s)->xofs)=(zfix)(value/10000);
16624
16625 84994 break;
16626
16627 case EWPNYOFS:
16628
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44193 times.
44193 if(0!=(s=checkEWpn(ri->ewpn)))
16629
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44193 times.
44193 (((weapon*)s)->yofs)=(zfix)(value/10000)+(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset);
16630
16631 44193 break;
16632
16633 case EWPNSHADOWXOFS:
16634 if(0!=(s=checkEWpn(ri->ewpn)))
16635 (((weapon*)s)->shadowxofs)=(zfix)(value/10000);
16636
16637 break;
16638
16639 case EWPNSHADOWYOFS:
16640 if(0!=(s=checkEWpn(ri->ewpn)))
16641 (((weapon*)s)->shadowyofs)=(zfix)(value/10000);
16642
16643 break;
16644
16645 case EWPNZOFS:
16646 if(0!=(s=checkEWpn(ri->ewpn)))
16647 (((weapon*)s)->zofs)=(zfix)(value/10000);
16648
16649 break;
16650
16651 case EWPNHXSZ:
16652
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 325611 times.
325611 if(0!=(s=checkEWpn(ri->ewpn)))
16653 325611 (((weapon*)s)->hit_width)=(value/10000);
16654
16655 325611 break;
16656
16657 case EWPNHYSZ:
16658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 325024 times.
325024 if(0!=(s=checkEWpn(ri->ewpn)))
16659 325024 (((weapon*)s)->hit_height)=(value/10000);
16660
16661 325024 break;
16662
16663 case EWPNHZSZ:
16664
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
44 if(0!=(s=checkEWpn(ri->ewpn)))
16665 44 (((weapon*)s)->hzsz)=(value/10000);
16666
16667 44 break;
16668
16669 case EWPNTXSZ:
16670
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 202345 times.
202345 if(0!=(s=checkEWpn(ri->ewpn)))
16671 202345 (((weapon*)s)->txsz)=vbound((value/10000),1,20);
16672
16673 202345 break;
16674
16675 case EWPNTYSZ:
16676
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 202345 times.
202345 if(0!=(s=checkEWpn(ri->ewpn)))
16677 202345 (((weapon*)s)->tysz)=vbound((value/10000),1,20);
16678
16679 202345 break;
16680
16681 case EWPNMISCD:
16682
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 2141187 times.
2142027 if(0!=(s=checkEWpn(ri->ewpn)))
16683 {
16684 2141187 int32_t a = vbound(ri->d[rINDEX]/10000,0,31);
16685 2141187 (((weapon*)(s))->miscellaneous[a])=value;
16686 2141187 }
16687
16688 2142027 break;
16689
16690 case EWPNCOLLDET:
16691
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31616 times.
31616 if(0!=(s=checkEWpn(ri->ewpn)))
16692 31616 (((weapon*)(s))->scriptcoldet)=value;
16693
16694 31616 break;
16695
16696 case EWPNENGINEANIMATE:
16697 if(0!=(s=checkEWpn(ri->ewpn)))
16698 (((weapon*)(s))->do_animation)=value;
16699
16700 break;
16701
16702
16703 case EWPNPARENTUID:
16704 if(0!=(s=checkEWpn(ri->ewpn)))
16705 (((weapon*)(s))->parent_uid) = value; //literal, not *10000
16706 break;
16707
16708 case EWPNPARENT:
16709 if(0!=(s=checkEWpn(ri->ewpn)))
16710 (((weapon*)(s))->parentid)= ( (get_qr(qr_OLDEWPNPARENT)) ? value / 10000 : value );
16711
16712 break;
16713
16714 case EWPNSCRIPT:
16715
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1621 times.
1621 if(0!=(s=checkEWpn(ri->ewpn)))
16716 {
16717 1621 (((weapon*)(s))->weaponscript)=vbound(value/10000,0,NUMSCRIPTWEAPONS-1);
16718
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1621 times.
1621 if ( get_qr(qr_CLEARINITDONSCRIPTCHANGE))
16719 {
16720
2/2
✓ Branch 0 taken 12968 times.
✓ Branch 1 taken 1621 times.
14589 for(int32_t q=0; q<8; q++)
16721 12968 (((weapon*)(s))->weap_initd[q]) = 0;
16722 1621 }
16723 1621 on_reassign_script_engine_data(ScriptType::Ewpn, ri->ewpn);
16724 1621 }
16725 1621 break;
16726
16727 case EWPNINITD:
16728 {
16729 4504 int32_t a = vbound((ri->d[rINDEX] / 10000),0,7);
16730
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4504 times.
4504 if(0!=(s=checkEWpn(ri->ewpn)))
16731 {
16732 4504 (((weapon*)(s))->weap_initd[a])=value;
16733 4504 }
16734 4504 break;
16735 }
16736 case EWPNFALLCLK:
16737 if(0!=(s=checkEWpn(ri->ewpn)))
16738 {
16739 if(((weapon*)(s))->fallclk != 0 && value == 0)
16740 {
16741 ((weapon*)(s))->cs = ((weapon*)(s))->o_cset;
16742 ((weapon*)(s))->tile = ((weapon*)(s))->o_tile;
16743 }
16744 else if(((weapon*)(s))->fallclk == 0 && value != 0) ((weapon*)(s))->o_cset = ((weapon*)(s))->cs;
16745 ((weapon*)(s))->fallclk = vbound(value/10000,0,70);
16746 }
16747 break;
16748 case EWPNFALLCMB:
16749 if(0!=(s=checkEWpn(ri->ewpn)))
16750 {
16751 ((weapon*)(s))->fallCombo = vbound(value/10000,0,MAXCOMBOS-1);
16752 }
16753 break;
16754 case EWPNDROWNCLK:
16755 if(0!=(s=checkEWpn(ri->ewpn)))
16756 {
16757 if(((weapon*)(s))->drownclk != 0 && value == 0)
16758 {
16759 ((weapon*)(s))->cs = ((weapon*)(s))->o_cset;
16760 ((weapon*)(s))->tile = ((weapon*)(s))->o_tile;
16761 }
16762 else if(((weapon*)(s))->drownclk == 0 && value != 0) ((weapon*)(s))->o_cset = ((weapon*)(s))->cs;
16763 ((weapon*)(s))->drownclk = vbound(value/10000,0,70);
16764 }
16765 break;
16766 case EWPNDROWNCMB:
16767 if(0!=(s=checkEWpn(ri->ewpn)))
16768 {
16769 ((weapon*)(s))->drownCombo = vbound(value/10000,0,MAXCOMBOS-1);
16770 }
16771 break;
16772 case EWPNFAKEZ:
16773 if(0!=(s=checkEWpn(ri->ewpn)))
16774 {
16775 ((weapon*)s)->fakez=get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000);
16776 if(((weapon*)s)->fakez < 0) ((weapon*)s)->fakez = 0_zf;
16777 }
16778
16779 break;
16780
16781 case EWPNMOVEFLAGS:
16782 {
16783 if(0!=(s=checkEWpn(ri->ewpn)))
16784 {
16785 int32_t indx = ri->d[rINDEX]/10000;
16786 if(BC::checkIndex(indx, 0, 10) == SH::_NoError)
16787 {
16788 //All bits, in order, of a single byte; just use bitwise
16789 move_flags bit = (move_flags)(1<<indx);
16790 if(value)
16791 ((weapon*)(s))->moveflags |= bit;
16792 else
16793 ((weapon*)(s))->moveflags &= ~bit;
16794 }
16795 }
16796 break;
16797 }
16798 case EWPNFLAGS:
16799 {
16800 if(0!=(s=checkEWpn(ri->ewpn)))
16801 {
16802 int32_t indx = ri->d[rINDEX]/10000;
16803 if(BC::checkIndex(indx, 0, WFLAG_MAX-1) == SH::_NoError)
16804 {
16805 //All bits, in order, of a single byte; just use bitwise
16806 weapon_flags bit = weapon_flags(1<<indx);
16807 if(value)
16808 ((weapon*)(s))->misc_wflags |= bit;
16809 else
16810 ((weapon*)(s))->misc_wflags &= ~bit;
16811 }
16812 }
16813 break;
16814 }
16815 case EWPNSPRITES:
16816 {
16817 if(0!=(s=checkEWpn(ri->ewpn)))
16818 {
16819 int32_t indx = ri->d[rINDEX]/10000;
16820 if(BC::checkIndex(indx, 0, WPNSPR_MAX-1) == SH::_NoError)
16821 ((weapon*)(s))->misc_wsprites[indx] = vbound(value/10000,0,255);
16822 }
16823 break;
16824 }
16825 case EWPNBURNLIGHTRADIUS:
16826 {
16827 if(0!=(s=checkEWpn(ri->ewpn)))
16828 {
16829 int32_t indx = ri->d[rINDEX]/10000;
16830 if(BC::checkIndex(indx, 0, WPNSPR_MAX-1) == SH::_NoError)
16831 ((weapon*)(s))->light_rads[indx] = vbound(value/10000,0,255);
16832 }
16833 break;
16834 }
16835
16836 case EWPNGLOWRAD:
16837
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(0!=(s=checkEWpn(ri->ewpn)))
16838 {
16839 4 ((weapon*)(s))->glowRad = vbound(value/10000,0,255);
16840 4 }
16841 4 break;
16842 case EWPNGLOWSHP:
16843 if(0!=(s=checkEWpn(ri->ewpn)))
16844 {
16845 ((weapon*)(s))->glowShape = vbound(value/10000,0,255);
16846 }
16847 break;
16848
16849 case EWPNUNBL:
16850 if(0!=(s=checkEWpn(ri->ewpn)))
16851 {
16852 ((weapon*)(s))->unblockable = (value/10000)&WPNUNB_ALL;
16853 }
16854 break;
16855
16856 case EWPNSHADOWSPR:
16857 if(0!=(s=checkEWpn(ri->ewpn)))
16858 {
16859 ((weapon*)(s))->spr_shadow = vbound(value/10000, 0, 255);
16860 }
16861 break;
16862 case EWSWHOOKED:
16863 break; //read-only
16864 case EWPNTIMEOUT:
16865 if(0!=(s=checkEWpn(ri->ewpn)))
16866 {
16867 ((weapon*)(s))->weap_timeout = vbound(value/10000,0,214748);
16868 }
16869 break;case EWPNDEATHITEM:
16870 if(0!=(s=checkEWpn(ri->ewpn)))
16871 {
16872 ((weapon*)(s))->death_spawnitem = vbound(value/10000,-1,MAXITEMS-1);
16873 }
16874 break;
16875 case EWPNDEATHDROPSET:
16876 if(0!=(s=checkEWpn(ri->ewpn)))
16877 {
16878 ((weapon*)(s))->death_spawndropset = vbound(value/10000,-1,MAXITEMDROPSETS-1);
16879 }
16880 break;
16881 case EWPNDEATHIPICKUP:
16882 if(0!=(s=checkEWpn(ri->ewpn)))
16883 {
16884 ((weapon*)(s))->death_item_pflags = value/10000;
16885 }
16886 break;
16887 case EWPNDEATHSPRITE:
16888 if(0!=(s=checkEWpn(ri->ewpn)))
16889 {
16890 ((weapon*)(s))->death_sprite = vbound(value/10000,-255,MAXWPNS-1);
16891 }
16892 break;
16893 case EWPNDEATHSFX:
16894 if(0!=(s=checkEWpn(ri->ewpn)))
16895 {
16896 ((weapon*)(s))->death_sfx = vbound(value/10000,0,WAV_COUNT);
16897 }
16898 break;
16899 case EWPNLIFTLEVEL:
16900 if(0!=(s=checkEWpn(ri->ewpn)))
16901 {
16902 ((weapon*)(s))->lift_level = vbound(value/10000,0,255);
16903 }
16904 break;
16905 case EWPNLIFTTIME:
16906 if(0!=(s=checkEWpn(ri->ewpn)))
16907 {
16908 ((weapon*)(s))->lift_time = vbound(value/10000,0,255);
16909 }
16910 break;
16911 case EWPNLIFTHEIGHT:
16912 if(0!=(s=checkEWpn(ri->ewpn)))
16913 {
16914 ((weapon*)(s))->lift_height = zslongToFix(value);
16915 }
16916 break;
16917
16918 ///----------------------------------------------------------------------------------------------------//
16919 //Screen Information
16920
16921 case SCREENSTATED:
16922 {
16923 799 int mi = mapind(cur_map, ri->screenref);
16924
2/2
✓ Branch 0 taken 788 times.
✓ Branch 1 taken 11 times.
799 (value)?setmapflag_mi(mi, 1<<((ri->d[rINDEX])/10000)) : unsetmapflag_mi(mi, 1 << ((ri->d[rINDEX]) / 10000));
16925 }
16926 799 break;
16927 case SCREENEXSTATED:
16928 {
16929 2 int mi = mapind(cur_map, ri->screenref);
16930
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 (value)?setxmapflag_mi(mi, 1<<((ri->d[rINDEX])/10000)) : unsetxmapflag_mi(mi, 1 << ((ri->d[rINDEX]) / 10000));
16931 }
16932 2 break;
16933 case SCREENLENSSHOWS:
16934 {
16935 int ind = ri->d[rINDEX]/10000;
16936 if(ind < 0 || ind > 6)
16937 Z_scripterrlog("Bad index Screen->LensShows[%d]\n",ind);
16938 else
16939 {
16940 SETFLAG(get_scr(ri->screenref)->lens_show, 1<<ind, value);
16941 if(value) get_scr(ri->screenref)->lens_hide &= ~(1<<ind);
16942 }
16943 break;
16944 }
16945 case SCREENLENSHIDES:
16946 {
16947 int ind = ri->d[rINDEX]/10000;
16948 if(ind < 0 || ind > 6)
16949 Z_scripterrlog("Bad index Screen->LensHides[%d]\n",ind);
16950 else
16951 {
16952 SETFLAG(get_scr(ri->screenref)->lens_hide, 1<<ind, value);
16953 if(value) get_scr(ri->screenref)->lens_show &= ~(1<<ind);
16954 }
16955 break;
16956 }
16957 case SCREENSCRDATASIZE:
16958 {
16959 int index = map_screen_index(cur_map, ri->screenref);
16960 if (index < 0) break;
16961
16962 game->scriptDataResize(index, value/10000);
16963 break;
16964 }
16965 case SCREENSCRDATA:
16966 {
16967 int mapindex = map_screen_index(cur_map, ri->screenref);
16968 if (mapindex < 0) break;
16969
16970 size_t indx = ri->d[rINDEX]/10000;
16971 if (indx >= game->scriptDataSize(mapindex))
16972 {
16973 Z_scripterrlog("Invalid index passed to Screen->Data[]: %d\n", indx);
16974 break;
16975 }
16976 game->screen_data[mapindex][indx] = value;
16977 break;
16978 }
16979
16980 case GAMEGUYCOUNTD:
16981 {
16982 int mi = mapind(cur_map, ri->d[rINDEX] / 10000);
16983 game->guys[mi] = value / 10000;
16984 break;
16985 }
16986
16987 ///----------------------------------------------------------------------------------------------------//
16988 //BottleTypes
16989 case BOTTLECOUNTER:
16990 {
16991 if(bottletype* ptr = checkBottleData(ri->bottletyperef))
16992 {
16993 int32_t indx = ri->d[rINDEX]/10000;
16994 int32_t ctr = vbound(value/10000, -1, MAX_COUNTERS-1);
16995 if(unsigned(indx) > 2)
16996 {
16997 Z_scripterrlog("Invalid index %d supplied to bottledata->Counter[].\n", indx);
16998 break;
16999 }
17000 ptr->counter[indx] = ctr;
17001 }
17002 }
17003 break;
17004
17005 case BOTTLEAMOUNT:
17006 {
17007 if(bottletype* ptr = checkBottleData(ri->bottletyperef))
17008 {
17009 int32_t indx = ri->d[rINDEX]/10000;
17010 int32_t amnt = vbound(value/10000, 0, 65535);
17011 if(unsigned(indx) > 2)
17012 {
17013 Z_scripterrlog("Invalid index %d supplied to bottledata->Amount[].\n", indx);
17014 break;
17015 }
17016 ptr->amount[indx] = amnt;
17017 }
17018 }
17019 break;
17020
17021 case BOTTLEPERCENT:
17022 {
17023 if(bottletype* ptr = checkBottleData(ri->bottletyperef))
17024 {
17025 int32_t indx = ri->d[rINDEX]/10000;
17026 if(unsigned(indx) > 2)
17027 {
17028 Z_scripterrlog("Invalid index %d supplied to bottledata->IsPercent[].\n", indx);
17029 break;
17030 }
17031 SETFLAG(ptr->flags, 1<<indx, value);
17032 }
17033 }
17034 break;
17035
17036 case BOTTLEFLAGS:
17037 {
17038 if(bottletype* ptr = checkBottleData(ri->bottletyperef))
17039 {
17040 int32_t indx = ri->d[rINDEX]/10000;
17041 if(unsigned(indx) > 3)
17042 {
17043 Z_scripterrlog("Invalid index %d supplied to bottledata->Flags[].\n", indx);
17044 break;
17045 }
17046 int32_t flag = 0;
17047 switch(indx)
17048 {
17049 case 0: flag = BTFLAG_AUTOONDEATH; break;
17050 case 1: flag = BTFLAG_ALLOWIFFULL; break;
17051 case 2: flag = BTFLAG_CURESWJINX; break;
17052 case 3: flag = BTFLAG_CUREITJINX; break;
17053 case 4: flag = BTFLAG_CURESHJINX; break;
17054 }
17055 SETFLAG(ptr->flags, flag, value);
17056 }
17057 }
17058 break;
17059
17060 case BOTTLENEXT:
17061 {
17062 if(bottletype* ptr = checkBottleData(ri->bottletyperef))
17063 {
17064 ptr->next_type = vbound(value/10000, 0, 64);
17065 }
17066 }
17067 break;
17068 ///----------------------------------------------------------------------------------------------------//
17069 //BottleShops
17070 case BSHOPFILL:
17071 {
17072 if(bottleshoptype* ptr = checkBottleShopData(ri->bottleshopref))
17073 {
17074 int32_t indx = ri->d[rINDEX]/10000;
17075 if(unsigned(indx) > 2)
17076 {
17077 scripting_log_error_with_context("Invalid index: {}", indx);
17078 break;
17079 }
17080 ptr->fill[indx] = vbound(value/10000, 0, 64);
17081 }
17082 }
17083 break;
17084
17085 case BSHOPCOMBO:
17086 {
17087 if(bottleshoptype* ptr = checkBottleShopData(ri->bottleshopref))
17088 {
17089 int32_t indx = ri->d[rINDEX]/10000;
17090 if(unsigned(indx) > 2)
17091 {
17092 scripting_log_error_with_context("Invalid index: {}", indx);
17093 break;
17094 }
17095 ptr->comb[indx] = vbound(value/10000, 0, MAXCOMBOS-1);
17096 }
17097 }
17098 break;
17099
17100 case BSHOPCSET:
17101 {
17102 if(bottleshoptype* ptr = checkBottleShopData(ri->bottleshopref))
17103 {
17104 int32_t indx = ri->d[rINDEX]/10000;
17105 if(unsigned(indx) > 2)
17106 {
17107 scripting_log_error_with_context("Invalid index: {}", indx);
17108 break;
17109 }
17110 ptr->cset[indx] = vbound(value/10000, 0, 11);
17111 }
17112 }
17113 break;
17114
17115 case BSHOPPRICE:
17116 {
17117 if(bottleshoptype* ptr = checkBottleShopData(ri->bottleshopref))
17118 {
17119 int32_t indx = ri->d[rINDEX]/10000;
17120 if(unsigned(indx) > 2)
17121 {
17122 scripting_log_error_with_context("Invalid index: {}", indx);
17123 break;
17124 }
17125 ptr->price[indx] = vbound(value/10000, 0, 65535);
17126 }
17127 }
17128 break;
17129
17130 case BSHOPSTR:
17131 {
17132 if(bottleshoptype* ptr = checkBottleShopData(ri->bottleshopref))
17133 {
17134 int32_t indx = ri->d[rINDEX]/10000;
17135 if(unsigned(indx) > 2)
17136 {
17137 scripting_log_error_with_context("Invalid index: {}", indx);
17138 break;
17139 }
17140 ptr->str[indx] = vbound(value/10000, 0, 65535);
17141 }
17142 }
17143 break;
17144
17145 ///----------------------------------------------------------------------------------------------------//
17146 //Screen->ComboX
17147 case COMBODD:
17148 {
17149 511648 int32_t pos = (ri->d[rINDEX])/10000;
17150 511648 rpos_t rpos = (rpos_t)pos;
17151 511648 int32_t val = (value/10000);
17152
1/2
✓ Branch 0 taken 511648 times.
✗ Branch 1 not taken.
511648 if (!is_valid_rpos(rpos))
17153 {
17154 Z_scripterrlog("Invalid [pos] %d used to write to Screen->ComboD[]\n", pos);
17155 }
17156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 511648 times.
511648 else if ( ((unsigned) val) >= MAXCOMBOS )
17157 {
17158 Z_scripterrlog("Invalid combo ID %d used to write to Screen->ComboD[]\n", val);
17159 }
17160 else
17161 {
17162 511648 auto rpos_handle = get_rpos_handle(rpos, 0);
17163 511648 screen_combo_modify_preroutine(rpos_handle);
17164 511648 rpos_handle.set_data(val);
17165 511648 screen_combo_modify_postroutine(rpos_handle);
17166 }
17167 }
17168 511648 break;
17169
17170 case COMBOCD:
17171 {
17172 27516 int32_t pos = (ri->d[rINDEX])/10000;
17173 27516 rpos_t rpos = (rpos_t)pos;
17174 27516 int32_t val = (value/10000); //cset
17175
1/2
✓ Branch 0 taken 27516 times.
✗ Branch 1 not taken.
27516 if (!is_valid_rpos(rpos))
17176 {
17177 Z_scripterrlog("Invalid pos %d used to write to Screen->ComboC[]\n", pos);
17178 }
17179
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27516 times.
27516 else if ( ((unsigned) val) >= 15 )
17180 {
17181 Z_scripterrlog("Invalid CSet ID %d used to write to Screen->ComboC[]\n", val);
17182 }
17183 else
17184 {
17185 27516 auto rpos_handle = get_rpos_handle(rpos, 0);
17186 27516 screen_combo_modify_preroutine(rpos_handle);
17187 27516 rpos_handle.set_cset(val&15);
17188 27516 screen_combo_modify_postroutine(rpos_handle);
17189 }
17190 }
17191 27516 break;
17192
17193 case COMBOFD:
17194 {
17195 5233 int32_t pos = (ri->d[rINDEX])/10000;
17196 5233 int32_t val = (value/10000); //flag
17197
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5233 times.
5233 if ( ((unsigned) pos) > 175 )
17198 {
17199 Z_scripterrlog("Invalid [pos] %d used to write to Screen->ComboF[]\n", pos);
17200 }
17201
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5233 times.
5233 else if ( ((unsigned) val) >= 256 )
17202 {
17203 Z_scripterrlog("Invalid Flag ID %d used to write to Screen->ComboF[]\n", val);
17204 }
17205
17206 else
17207 5233 get_scr(ri->screenref)->sflag[pos]=(val);
17208 }
17209 5233 break;
17210
17211 case COMBOTD:
17212 {
17213 3646 int32_t pos = (ri->d[rINDEX])/10000;
17214 3646 int32_t val = (value/10000); //type
17215
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3646 times.
3646 if ( ((unsigned) pos) > 175 )
17216 {
17217 Z_scripterrlog("Invalid [pos] %d used to write to Screen->ComboT[]\n", pos);
17218 }
17219
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3646 times.
3646 else if ( ((unsigned) val) >= 256 )
17220 {
17221 Z_scripterrlog("Invalid Flag ID %d used to write to Screen->ComboT[]\n", val);
17222 }
17223 else
17224 {
17225 3646 mapscr* scr = get_scr(ri->screenref);
17226 3646 int cid = scr->data[pos];
17227 3646 screen_combo_modify_pre(cid);
17228 3646 combobuf[cid].type=val;
17229 3646 screen_combo_modify_post(cid);
17230 }
17231 }
17232 3646 break;
17233
17234 case COMBOID:
17235 {
17236 int32_t pos = (ri->d[rINDEX])/10000;
17237 int32_t val = (value/10000); //iflag
17238 if ( ((unsigned) pos) > 175 )
17239 {
17240 Z_scripterrlog("Invalid [pos] %d used to write to Screen->ComboI[]\n", pos);
17241 }
17242 else if ( ((unsigned) val) >= 256 )
17243 {
17244 Z_scripterrlog("Invalid Flag ID %d used to write to Screen->ComboI[]\n", val);
17245 }
17246 else
17247 combobuf[get_scr(ri->screenref)->data[pos]].flag=val;
17248 }
17249 break;
17250
17251 case COMBOSD:
17252 {
17253 81346 int32_t pos = (ri->d[rINDEX])/10000;
17254 81346 int32_t val = (value/10000); //iflag
17255
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 81346 times.
81346 if ( ((unsigned) pos) > 175 )
17256 {
17257 Z_scripterrlog("Invalid [pos] %d used to write to Screen->ComboS[]\n", pos);
17258 }
17259
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 81346 times.
81346 else if ( ((unsigned) val) >= 16 )//solidity 1, 2, 4, 8 max 15
17260 {
17261 Z_scripterrlog("Invalid Flag ID %d used to write to Screen->ComboS[]\n", val);
17262 }
17263 else
17264 {
17265 81346 mapscr* scr = get_scr(ri->screenref);
17266 81346 combobuf[scr->data[pos]].walk &= ~0x0F;
17267 81346 combobuf[scr->data[pos]].walk |= (val)&0x0F;
17268 }
17269 }
17270 81346 break;
17271
17272 case COMBOED:
17273 {
17274 int32_t pos = (ri->d[rINDEX])/10000;
17275 int32_t val = (value/10000); //iflag
17276 if ( ((unsigned) pos) > 175 )
17277 {
17278 Z_scripterrlog("Invalid [pos] %d used to write to Screen->ComboE[]\n", pos);
17279 }
17280 else if ( ((unsigned) val) >= 16 )//solidity 1, 2, 4, 8 max 15
17281 {
17282 Z_scripterrlog("Invalid Flag ID %d used to write to Screen->ComboE[]\n", val);
17283 }
17284 else
17285 {
17286 mapscr* scr = get_scr(ri->screenref);
17287 combobuf[scr->data[pos]].walk &= ~0xF0;
17288 combobuf[scr->data[pos]].walk |= ((val)&0x0F)<<4;
17289 }
17290 }
17291 break;
17292
17293 ///----------------------------------------------------------------------------------------------------//
17294 //Viewport
17295
17296 case VIEWPORT_TARGET:
17297 {
17298
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (auto s = ResolveBaseSprite(value))
17299 6 set_viewport_sprite(s);
17300 }
17301 6 break;
17302
17303 case VIEWPORT_MODE:
17304 {
17305 4 int val = value;
17306
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (BC::checkBounds(val, (int)ViewportMode::First, (int)ViewportMode::Last) != SH::_NoError)
17307 {
17308 break;
17309 }
17310
17311 4 viewport_mode = (ViewportMode)val;
17312 }
17313 4 break;
17314
17315 case VIEWPORT_X:
17316 {
17317 360 viewport.x = value / 10000;
17318 }
17319 360 break;
17320
17321 case VIEWPORT_Y:
17322 {
17323 360 viewport.y = value / 10000;
17324 }
17325 360 break;
17326
17327 case VIEWPORT_WIDTH:
17328 {
17329 int val = value / 10000;
17330 if (BC::checkBounds(val, 0, 256) != SH::_NoError)
17331 break;
17332
17333 viewport.w = val;
17334 }
17335 break;
17336
17337 case VIEWPORT_HEIGHT:
17338 {
17339 int val = value / 10000;
17340 if (BC::checkBounds(val, 0, 232) != SH::_NoError)
17341 break;
17342
17343 viewport.h = val;
17344 }
17345 break;
17346
17347 ///----------------------------------------------------------------------------------------------------//
17348 //Screen Variables
17349
17350 #define SET_SCREENDATA_VAR_INT32(member, str) \
17351 { \
17352 get_scr(ri->screenref)->member = vbound((value / 10000),-214747,214747); \
17353 } \
17354
17355 #define SET_SCREENDATA_VAR_INT16(member, str) \
17356 { \
17357 get_scr(ri->screenref)->member = vbound((value / 10000),0,32767); \
17358 } \
17359
17360 #define SET_SCREENDATA_VAR_BYTE(member, str) \
17361 { \
17362 get_scr(ri->screenref)->member = vbound((value / 10000),0,255); \
17363 } \
17364
17365 #define SET_SCREENDATA_VAR_INDEX32(member, str, indexbound) \
17366 { \
17367 int32_t indx = ri->d[rINDEX] / 10000; \
17368 get_scr(ri->screenref)->member[indx] = vbound((value / 10000),-214747,214747); \
17369 } \
17370
17371 #define SET_SCREENDATA_VAR_INDEX16(member, str, indexbound) \
17372 { \
17373 int32_t indx = ri->d[rINDEX] / 10000; \
17374 get_scr(ri->screenref)->member[indx] = vbound((value / 10000),-32767,32767); \
17375 } \
17376
17377 #define SET_SCREENDATA_BYTE_INDEX(member, str, indexbound) \
17378 { \
17379 int32_t indx = ri->d[rINDEX] / 10000; \
17380 get_scr(ri->screenref)->member[indx] = vbound((value / 10000),0,255); \
17381 }
17382 #define SET_SCREENDATA_LAYER_INDEX(member, str, indexbound) \
17383 { \
17384 int32_t indx = ri->d[rINDEX] / 10000; \
17385 if ( FFCore.quest_format[vFFScript] < 11 ) ++indx; \
17386 if (BC::checkIndex(indx, 1, indexbound) == SH::_NoError) \
17387 { \
17388 get_scr(ri->screenref)->member[indx-1] = vbound((value / 10000),0,255); \
17389 } \
17390 }
17391 ///max screen id is higher! vbound properly... -Z
17392 #define SET_SCREENDATA_LAYERSCREEN_INDEX(member, str, indexbound) \
17393 { \
17394 int32_t indx = ri->d[rINDEX] / 10000; \
17395 int32_t scrn_id = value/10000; \
17396 if ( FFCore.quest_format[vFFScript] < 11 ) ++indx; \
17397 if (BC::checkIndex(indx, 1, indexbound) != SH::_NoError) \
17398 { \
17399 } \
17400 else if ( scrn_id > MAPSCRS ) \
17401 { \
17402 Z_scripterrlog("Script attempted to use a mapdata->LayerScreen[%d].\n",scrn_id); \
17403 Z_scripterrlog("Valid Screen values are (0) through (%d).\n",MAPSCRS); \
17404 } \
17405 else get_scr(ri->screenref)->member[indx-1] = vbound((scrn_id),0,MAPSCRS); \
17406 }
17407
17408 #define SET_SCREENDATA_FLAG(member, str) \
17409 { \
17410 int32_t flag = (value/10000); \
17411 if ( flag != 0 ) \
17412 { \
17413 get_scr(ri->screenref)->member|=flag; \
17414 } \
17415 else get_scr(ri->screenref)->.member|= ~flag; \
17416 } \
17417
17418 #define SET_SCREENDATA_BOOL_INDEX(member, str, indexbound) \
17419 { \
17420 int32_t indx = ri->d[rINDEX] / 10000; \
17421 if(indx < 0 || indx > indexbound ) \
17422 { \
17423 Z_scripterrlog("Invalid Index passed to Screen->%s[]: %d\n", (indx), str); \
17424 break; \
17425 } \
17426 get_scr(ri->screenref)->member[indx] =( (value/10000) ? 1 : 0 ); \
17427 }
17428
17429 case SCREENDATAVALID:
17430 {
17431 SET_SCREENDATA_VAR_BYTE(valid, "Valid"); //b
17432 mark_current_region_handles_dirty();
17433 break;
17434 }
17435 case SCREENDATAGUY: SET_SCREENDATA_VAR_BYTE(guy, "Guy"); break; //b
17436 case SCREENDATASTRING: SET_SCREENDATA_VAR_INT32(str, "String"); break; //w
17437 case SCREENDATAROOM: SET_SCREENDATA_VAR_BYTE(room, "RoomType"); break; //b
17438 case SCREENDATAITEM:
17439 {
17440 auto v = vbound((value / 10000),-1,255);
17441 auto scr = get_scr(ri->screenref);
17442 if(v > -1)
17443 scr->item = v;
17444 scr->hasitem = v > -1;
17445 break;
17446 }
17447 case SCREENDATAHASITEM: SET_SCREENDATA_VAR_BYTE(hasitem, "HasItem"); break; //b
17448 case SCREENDATATILEWARPTYPE: SET_SCREENDATA_BYTE_INDEX(tilewarptype, "TileWarpType", 3); break; //b, 4 of these
17449 //case SCREENDATATILEWARPOVFLAGS: SET_SCREENDATA_VAR_BYTE(tilewarpoverlayflags, "TileWarpOverlayFlags"); break; //b, tilewarpoverlayflags
17450 case SCREENDATADOORCOMBOSET: SET_SCREENDATA_VAR_INT32(door_combo_set, "DoorComboSet"); break; //w
17451 case SCREENDATAWARPRETX: SET_SCREENDATA_BYTE_INDEX(warpreturnx, "WarpReturnX", 3); break; //b, 4 of these
17452 case SCREENDATAWARPRETY: SET_SCREENDATA_BYTE_INDEX(warpreturny, "WarpReturnY", 3); break; //b, 4 of these
17453 case SCREENDATAWARPRETURNC: SET_SCREENDATA_VAR_INT32(warpreturnc, "WarpReturnC"); break; //w
17454 case SCREENDATASTAIRX: SET_SCREENDATA_VAR_BYTE(stairx, "StairsX"); break; //b
17455 case SCREENDATASTAIRY: SET_SCREENDATA_VAR_BYTE(stairy, "StairsY"); break; //b
17456 case SCREENDATAITEMX: SET_SCREENDATA_VAR_BYTE(itemx, "ItemX"); break; //itemx
17457 case SCREENDATAITEMY: SET_SCREENDATA_VAR_BYTE(itemy, "ItemY"); break; //itemy
17458 case SCREENDATACOLOUR: SET_SCREENDATA_VAR_INT32(color, "CSet"); break; //w
17459 case SCREENDATAENEMYFLAGS: SET_SCREENDATA_VAR_BYTE(flags11, "EnemyFlags"); break; //b
17460 case SCREENDATADOOR: SET_SCREENDATA_BYTE_INDEX(door, "Door", 3); break; //b, 4 of these
17461 case SCREENDATATILEWARPDMAP: SET_SCREENDATA_VAR_INDEX32(tilewarpdmap, "TileWarpDMap", 3); break; //w, 4 of these
17462 case SCREENDATATILEWARPSCREEN: SET_SCREENDATA_BYTE_INDEX(tilewarpscr, "TileWarpScreen", 3); break; //b, 4 of these
17463 case SCREENDATAEXITDIR: SET_SCREENDATA_VAR_BYTE(exitdir, "ExitDir"); break; //b
17464 case SCREENDATAENEMY:
17465 {
17466 int32_t indx = ri->d[rINDEX] / 10000;
17467 int32_t enemyid = value/10000;
17468 if ( ((unsigned)enemyid) > MAXGUYS )
17469 {
17470 Z_scripterrlog("Invaid enemy ID (%d) passed to Screen->%s.", enemyid,"Enemy[]"); \
17471 break;
17472 }
17473 if(unsigned(indx) > 9)
17474 {
17475 Z_scripterrlog("Invalid index (%d) used for Screen->Enemy[]", indx);
17476 break;
17477 }
17478 mapscr* scr = get_scr(ri->screenref);
17479 scr->enemy[indx] = enemyid;
17480 break;
17481 }
17482 //case SCREENDATAENEMY: SET_SCREENDATA_VAR_INDEX32(enemy, "Enemy", 9); break; //w, 10 of these
17483 case SCREENDATAPATTERN: SET_SCREENDATA_VAR_BYTE(pattern, "Pattern"); break; //b
17484 138 case SCREENDATASIDEWARPTYPE: SET_SCREENDATA_BYTE_INDEX(sidewarptype, "SideWarpType", 3); break; //b, 4 of these
17485 //case SCREENDATASIDEWARPOVFLAGS: SET_SCREENDATA_VAR_BYTE(sidewarpoverlayflags, "SideWarpOverlayFlags"); break; //b
17486 case SCREENDATAWARPARRIVALX: SET_SCREENDATA_VAR_BYTE(warparrivalx, "WarpArrivalX"); break; //b
17487 case SCREENDATAWARPARRIVALY: SET_SCREENDATA_VAR_BYTE(warparrivaly, "WarpArrivalY"); break; //b
17488 case SCREENDATAPATH: SET_SCREENDATA_BYTE_INDEX(path, "MazePath", 3); break; //b, 4 of these
17489 case SCREENDATASIDEWARPSC: SET_SCREENDATA_BYTE_INDEX(sidewarpscr, "SideWarpScreen", 3); break; //b, 4 of these
17490 case SCREENDATASIDEWARPDMAP: SET_SCREENDATA_VAR_INDEX32(sidewarpdmap, "SideWarpDMap", 3); break; //w, 4 of these
17491 case SCREENDATASIDEWARPINDEX: SET_SCREENDATA_VAR_BYTE(sidewarpindex, "SideWarpIndex"); break; //b
17492 case SCREENDATAUNDERCOMBO: SET_SCREENDATA_VAR_INT32(undercombo, "Undercombo"); break; //w
17493 case SCREENDATAUNDERCSET: SET_SCREENDATA_VAR_BYTE(undercset, "UnderCSet"); break; //b
17494 case SCREENDATACATCHALL: SET_SCREENDATA_VAR_INT32(catchall, "Catchall"); break; //W
17495
17496 case SCREENDATACSENSITIVE: SET_SCREENDATA_VAR_BYTE(csensitive, "CSensitive"); break; //B
17497 case SCREENDATANORESET: SET_SCREENDATA_VAR_INT32(noreset, "NoReset"); break; //W
17498 case SCREENDATANOCARRY: SET_SCREENDATA_VAR_INT32(nocarry, "NoCarry"); break; //W
17499 case SCREENDATALAYERMAP:
17500 {
17501 SET_SCREENDATA_LAYER_INDEX(layermap, "LayerMap", 5); //B, 6 OF THESE
17502 mark_current_region_handles_dirty();
17503 break;
17504 }
17505 case SCREENDATALAYERSCREEN:
17506 {
17507 SET_SCREENDATA_LAYERSCREEN_INDEX(layerscreen, "LayerScreen", 5); //B, 6 OF THESE
17508 mark_current_region_handles_dirty();
17509 break;
17510 }
17511 case SCREENDATALAYEROPACITY: SET_SCREENDATA_LAYER_INDEX(layeropacity, "LayerOpacity", 5); break; //B, 6 OF THESE
17512 case SCREENDATALAYERINVIS:
17513 {
17514 103760 int32_t indx = ri->d[rINDEX] / 10000;
17515
2/4
✓ Branch 0 taken 103760 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 103760 times.
103760 if(indx < 0 || indx > 6 )
17516 {
17517 Z_scripterrlog("Invalid Index passed to Screen->LayerInvisible[]: %d\n", indx);
17518 }
17519 else
17520 {
17521
1/2
✓ Branch 0 taken 103760 times.
✗ Branch 1 not taken.
103760 if(value)
17522 103760 get_scr(ri->screenref)->hidelayers |= (1<<indx);
17523 else
17524 get_scr(ri->screenref)->hidelayers &= ~(1<<indx);
17525 }
17526 103760 break;
17527 }
17528 case SCREENDATASCRIPTDRAWS:
17529 {
17530 int32_t indx = ri->d[rINDEX] / 10000;
17531 if(indx < 0 || indx > 7 )
17532 {
17533 Z_scripterrlog("Invalid Index passed to Screen->HideScriptLayer[]: %d\n", indx);
17534 }
17535 else
17536 {
17537 if(value)
17538 get_scr(ri->screenref)->hidescriptlayers &= ~(1<<indx);
17539 else
17540 get_scr(ri->screenref)->hidescriptlayers |= (1<<indx);
17541 }
17542 break;
17543 }
17544
17545 case SCREENDATATILEWARPOVFLAGS:
17546 {
17547 int32_t indx = ri->d[rINDEX] / 10000;
17548 if ( ((unsigned)indx) > 3 )
17549 {
17550 Z_scripterrlog("Invalid index passed to TileWarpOverlayFlags[%d].\n. Valid indices are [0] through [3].\n", indx);
17551 }
17552 else
17553 {
17554 if ( value ) get_scr(ri->screenref)->tilewarpoverlayflags |= (1<<indx);
17555 else get_scr(ri->screenref)->tilewarpoverlayflags &= ~(1<<indx);
17556 }
17557 break;
17558 }
17559
17560 case SCREENDATASIDEWARPOVFLAGS:
17561 {
17562 int32_t indx = ri->d[rINDEX] / 10000;
17563 if ( ((unsigned)indx) > 3 )
17564 {
17565 Z_scripterrlog("Invalid index passed to SideWarpOverlayFlags[%d].\n. Valid indices are [0] through [3].\n", indx);
17566 }
17567 else
17568 {
17569 if ( value ) get_scr(ri->screenref)->sidewarpoverlayflags |= (1<<indx);
17570 else get_scr(ri->screenref)->sidewarpoverlayflags &= ~(1<<indx);
17571 }
17572 break;
17573 }
17574
17575 case SCREENDATATIMEDWARPTICS: SET_SCREENDATA_VAR_INT32(timedwarptics, "TimedWarpTimer"); break; //W
17576 case SCREENDATANEXTMAP: SET_SCREENDATA_VAR_BYTE(nextmap, "NextMap"); break; //B
17577 case SCREENDATANEXTSCREEN: SET_SCREENDATA_VAR_BYTE(nextscr, "NextScreen"); break; //B
17578 128 case SCREENDATASECRETCOMBO: SET_SCREENDATA_VAR_INDEX32(secretcombo, "SecretCombo", 127); break; //W, 128 OF THESE
17579 128 case SCREENDATASECRETCSET: SET_SCREENDATA_BYTE_INDEX(secretcset, "SecretCSet", 127); break; //B, 128 OF THESE
17580 128 case SCREENDATASECRETFLAG: SET_SCREENDATA_BYTE_INDEX(secretflag, "SecretFlags", 127); break; //B, 128 OF THESE
17581 case SCREENDATAVIEWX: break;//SET_SCREENDATA_VAR_INT32(viewX, "ViewX"); break; //W
17582 case SCREENDATAVIEWY: break;//SET_SCREENDATA_VAR_INT32(viewY, "ViewY"); break; //W
17583 case SCREENDATASCREENWIDTH: break;//SET_SCREENDATA_VAR_BYTE(scrWidth, "Width"); break; //B
17584 case SCREENDATASCREENHEIGHT: break;//SET_SCREENDATA_VAR_BYTE(scrHeight, "Height"); break; //B
17585 case SCREENDATAENTRYX:
17586 {
17587 30 int32_t newx = vbound((value/10000),0,255);
17588 30 get_scr(ri->screenref)->entry_x = newx;
17589
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 20 times.
30 if ( get_qr(qr_WRITE_ENTRYPOINTS_AFFECTS_HEROCLASS) )
17590 {
17591 20 Hero.respawn_x = (zfix)(newx);
17592 20 }
17593 30 break;
17594 }
17595 case SCREENDATAENTRYY:
17596 {
17597
17598 30 int32_t newy = vbound((value/10000),0,175);
17599 30 get_scr(ri->screenref)->entry_y = newy;
17600
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 20 times.
30 if ( get_qr(qr_WRITE_ENTRYPOINTS_AFFECTS_HEROCLASS) )
17601 {
17602 20 Hero.respawn_y = (zfix)(newy);
17603 20 }
17604 30 break; //B
17605 }
17606
17607 case SCREENDATANUMFF:
17608 {
17609 break;
17610 }
17611
17612 case SCREENDATAFFINITIALISED:
17613 {
17614 int32_t indx = ri->d[rINDEX] / 10000;
17615 if (indx < 0 || indx > MAX_FFCID)
17616 {
17617 Z_scripterrlog("Invalid Index passed to Screen->%s[]: %d\n", (indx), "FFCRunning");
17618 break;
17619 }
17620 get_script_engine_data(ScriptType::FFC, indx).initialized = (value/10000) ? true : false;
17621 }
17622 break;
17623
17624 case SCREENDATASCRIPTENTRY:
17625 {
17626 Z_scripterrlog("Unimplemented: %s\n", "ScriptEntry");
17627 }
17628 break;
17629 case SCREENDATASCRIPTOCCUPANCY:
17630 {
17631 Z_scripterrlog("Unimplemented: %s\n", "ScriptOccupancy");
17632 }
17633 break;
17634 case SCREENDATASCRIPTEXIT:
17635 {
17636 Z_scripterrlog("Unimplemented: %s\n", "ExitScript");
17637 }
17638 break;
17639
17640 case SCREENDATAOCEANSFX:
17641 {
17642 int32_t v = vbound(value/10000, 0, 255);
17643 auto scr = get_scr(ri->screenref);
17644 if (scr == hero_scr && scr->oceansfx != v)
17645 {
17646 stop_sfx(scr->oceansfx);
17647 scr->oceansfx = v;
17648 cont_sfx(scr->oceansfx);
17649 }
17650 break;
17651 }
17652 case SCREENDATABOSSSFX: SET_SCREENDATA_VAR_BYTE(bosssfx, "BossSFX"); break; //B
17653 10 case SCREENDATASECRETSFX: SET_SCREENDATA_VAR_BYTE(secretsfx, "SecretSFX"); break; //B
17654 case SCREENDATAHOLDUPSFX: SET_SCREENDATA_VAR_BYTE(holdupsfx, "ItemSFX"); break; //B
17655 case SCREENDATASCREENMIDI:
17656 {
17657 get_scr(ri->screenref)->screen_midi = vbound((value / 10000)-(MIDIOFFSET_MAPSCR-MIDIOFFSET_ZSCRIPT),-1,32767);
17658 break;
17659 }
17660 case SCREENDATALENSLAYER: SET_SCREENDATA_VAR_BYTE(lens_layer, "LensLayer"); break; //B, OLD QUESTS ONLY?
17661
17662 case SCREENSIDEWARPID:
17663 {
17664 2114 int32_t indx = ri->d[rINDEX] / 10000; //dir
17665
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2114 times.
2114 if (BC::checkBounds(indx, 0, 3) != BC::_NoError)
17666 break;
17667
17668 2114 int32_t new_warp_return = vbound((value / 10000),-1,3); //none, A, B, C, D
17669 2114 auto scr = get_scr(ri->screenref);
17670
2/2
✓ Branch 0 taken 1040 times.
✓ Branch 1 taken 1074 times.
2114 if(new_warp_return == -1)
17671 {
17672 1074 scr->flags2 &= ~(1<<indx); //Unset the "Enabled" flag for this dir
17673 1074 scr->sidewarpindex &= ~(3<<(2*indx)); //Clear the dir as well.
17674 1074 }
17675 else
17676 {
17677 1040 scr->flags2 |= 1<<indx; //Set the "Enabled" flag for this dir
17678 1040 scr->sidewarpindex &= ~(3<<(2*indx)); //Clear the dir bits
17679 1040 scr->sidewarpindex |= (new_warp_return<<(2*indx)); //Set the new dir
17680 }
17681
17682 2114 break;
17683 }
17684
17685 case SCREENDATATWARPRETSQR:
17686 {
17687 int32_t indx = ri->d[rINDEX] / 10000;
17688 if ( ((unsigned)indx) > 3)
17689 {
17690 Z_scripterrlog("Invalid Array Index passed to Screen->TileWarpReturnSquare[]: %d\n", indx);
17691 }
17692 else
17693 {
17694 auto scr = get_scr(ri->screenref);
17695 int32_t wrindex = vbound(value/10000, 0, 3);
17696 scr->warpreturnc = (scr->warpreturnc&~(3<<(indx*2))) | (wrindex<<(indx*2));
17697 }
17698 break;
17699 }
17700
17701 //
17702 case SCREENDATASWARPRETSQR:
17703 {
17704
17705 int32_t indx = ri->d[rINDEX] / 10000;
17706 if ( ((unsigned)indx) > 3)
17707 {
17708 Z_scripterrlog("Invalid Array Index passed to Screen->SideWarpReturnSquare[]: %d\n", indx);
17709 }
17710 else
17711 {
17712 auto scr = get_scr(ri->screenref);
17713 int32_t wrindex = vbound(value/10000, 0, 3);
17714 scr->warpreturnc = (scr->warpreturnc&~(3<<(8+(indx*2)))) | (wrindex<<(8+(indx*2)));
17715 }
17716 break;
17717 }
17718
17719
17720 case SCREENDATAFLAGS:
17721 {
17722 auto scr = get_scr(ri->screenref);
17723 int32_t flagid = (ri->d[rINDEX])/10000;
17724 //bool valtrue = ( value ? 10000 : 0);
17725 switch(flagid)
17726 {
17727 case 0: scr->flags = (value / 10000); break;
17728 case 1: scr->flags2 = (value / 10000); break;
17729 case 2: scr->flags3 = (value / 10000); break;
17730 case 3: scr->flags4 = (value / 10000); break;
17731 case 4: scr->flags5 = (value / 10000); break;
17732 case 5: scr->flags6 = (value / 10000); break;
17733 case 6: scr->flags7 = (value / 10000); break;
17734 case 7: scr->flags8 = (value / 10000); break;
17735 case 8: scr->flags9 = (value / 10000); break;
17736 case 9: scr->flags10 = (value / 10000); break;
17737 case 10: scr->flags11 = (value / 10000); break;
17738 default:
17739 {
17740 Z_scripterrlog("Invalid index passed to mapdata->flags[]: %d\n", flagid);
17741 break;
17742
17743 }
17744 }
17745 break;
17746 }
17747
17748 case SCREENDATAGUYCOUNT:
17749 {
17750 int mi = mapind(cur_map, ri->screenref);
17751 if(mi > -1)
17752 game->guys[mi] = vbound(value/10000,10,0);
17753 break;
17754 }
17755 case SCREENDATAEXDOOR:
17756 {
17757 int mi = mapind(cur_map, ri->screenref);
17758 if(mi < 0) break;
17759 int dir = SH::read_stack(ri->sp+1) / 10000;
17760 int ind = SH::read_stack(ri->sp+0) / 10000;
17761 if(unsigned(dir) > 3)
17762 Z_scripterrlog("Invalid dir '%d' passed to 'Screen->SetExDoor()'; must be 0-3\n", dir);
17763 else if(unsigned(ind) > 7)
17764 Z_scripterrlog("Invalid index '%d' passed to 'Screen->SetExDoor()'; must be 0-7\n", ind);
17765 else
17766 set_xdoorstate_mi(mi, dir, ind);
17767 break;
17768 }
17769
17770 //These use the same method as SetScreenD
17771 case SCREENWIDTH:
17772 // FFScript::set_screenWidth(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)], value/10000);
17773 break;
17774
17775 case SCREENHEIGHT:
17776 // FFScript::set_screenHeight(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)], value/10000);
17777 break;
17778
17779 case SCREENVIEWX:
17780 // FFScript::set_screenViewX(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)], value/10000);
17781 break;
17782
17783 case SCREENVIEWY:
17784 // FFScript::set_screenViewY(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)], value/10000);
17785 break;
17786
17787 //These use the method of SetScreenEnemy
17788
17789 case SDD:
17790 {
17791 {
17792
2/2
✓ Branch 0 taken 24816 times.
✓ Branch 1 taken 1721 times.
26537 int32_t di2 = ((get_currdmap())<<7) + get_currscr()-(DMaps[get_currdmap()].type==dmOVERW ? 0 : DMaps[get_currdmap()].xoff);
17793 26537 FFScript::set_screen_d(di2, ri->d[rINDEX]/10000, value);
17794 26537 break;
17795 }
17796 }
17797
17798 case GDD:
17799 write_array(game->global_d, ri->d[rINDEX] / 10000, value);
17800 break;
17801
17802 case SDDD:
17803 27297 FFScript::set_screen_d((ri->d[rINDEX])/10000 + ((get_currdmap())<<7), ri->d[rINDEX2]/10000, value);
17804 27297 break;
17805
17806 case SDDDD:
17807 536 FFScript::set_screen_d(ri->d[rINDEX2]/10000 + ((ri->d[rINDEX]/10000)<<7), ri->d[rEXP1]/10000, value);
17808 536 break;
17809
17810 case SCREENINITD:
17811 write_array(get_scr(ri->screenref)->screeninitd, ri->d[rINDEX]/10000, value);
17812 break;
17813
17814 case SCREENSCRIPT:
17815 {
17816 mapscr* scr = get_scr(ri->screenref);
17817
17818 if ( get_qr(qr_CLEARINITDONSCRIPTCHANGE))
17819 {
17820 for(int32_t q=0; q<8; q++)
17821 scr->screeninitd[q] = 0;
17822 }
17823
17824 scr->script=vbound(value/10000, 0, NUMSCRIPTSCREEN-1);
17825 on_reassign_script_engine_data(ScriptType::Screen, ri->screenref);
17826 break;
17827 }
17828
17829 case SCRDOORD:
17830 {
17831 4 mapscr* scr = get_scr(ri->screenref);
17832 4 int index = ri->d[rINDEX]/10000;
17833 4 byte val = value/10000;
17834
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (write_array(scr->door, index, val))
17835 4 putdoor(scr, scrollbuf, index, val, true, true);
17836 4 break;
17837 }
17838
17839 case LIT:
17840 900 set_lights(value);
17841 900 break;
17842
17843 case WAVY:
17844 7396 wavy=value/10000;
17845 7396 break;
17846
17847 case QUAKE:
17848 6502 quakeclk=value/10000;
17849 6502 break;
17850
17851 case SCREEN_FLAG:
17852 {
17853 int32_t index = ri->d[rINDEX] / 10000;
17854 if (BC::checkIndex(index, 0, 8*11 - 1) != SH::_NoError)
17855 {
17856 break;
17857 }
17858
17859 mapscr* scr = get_scr(ri->screenref);
17860 byte& flag = (&scr->flags)[index/8];
17861 bool v = value;
17862 SETFLAG(flag, 1 << (index%8), v);
17863 break;
17864 }
17865
17866 case ROOMTYPE:
17867 get_scr(ri->screenref)->room=value/10000; break; //this probably doesn't work too well...
17868
17869 case ROOMDATA:
17870 11 get_scr(ri->screenref)->catchall=value/10000;
17871 11 break;
17872
17873 case PUSHBLOCKLAYER:
17874 mblock2.blockLayer=vbound(value/10000, 0, 6);
17875 break;
17876
17877 case PUSHBLOCKCOMBO:
17878 mblock2.bcombo=value/10000;
17879 break;
17880
17881 case PUSHBLOCKCSET:
17882 mblock2.cs=value/10000;
17883 mblock2.oldcset=value/10000;
17884 break;
17885
17886 case UNDERCOMBO:
17887 get_scr(ri->screenref)->undercombo=value/10000;
17888 break;
17889
17890 case UNDERCSET:
17891 get_scr(ri->screenref)->undercset=value/10000;
17892 break;
17893
17894 case SCREEN_DRAW_ORIGIN:
17895
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39294 times.
39294 if (BC::checkBounds(value, (int)DrawOrigin::First, (int)DrawOrigin::Last) != SH::_NoError)
17896 break;
17897
17898 39294 ri->screen_draw_origin = (DrawOrigin)value;
17899 39294 break;
17900
17901 case SCREEN_DRAW_ORIGIN_TARGET:
17902 {
17903
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5310 times.
5310 if (ResolveBaseSprite(value))
17904 5310 ri->screen_draw_origin_target = value;
17905
17906 5310 break;
17907 }
17908
17909 case DEBUGGDR:
17910 {
17911 int32_t a = vbound(ri->d[rINDEX]/10000,0,15);
17912 game->global_d[a] = value / 10000;;
17913 break;
17914 }
17915
17916 case DEBUGSP:
17917 SH::write_stack(ri->sp,vbound((value / 10000),0,MAX_SCRIPT_REGISTERS-1));
17918 break;
17919
17920 case DEBUGREFFFC:
17921 ri->ffcref = vbound((value / 10000),1,MAXFFCS-1);
17922 break;
17923
17924 case DEBUGREFITEM:
17925 ri->itemref = vbound((value / 10000),0,255);
17926 break;
17927
17928 case DEBUGREFITEMDATA:
17929 ri->idata = vbound((value / 10000),0,255);
17930 break;
17931
17932 case DEBUGREFLWEAPON:
17933 ri->lwpn = vbound((value / 10000),0,255);
17934 break;
17935
17936 case DEBUGREFEWEAPON:
17937 ri->ewpn = vbound((value / 10000),0,255);
17938 break;
17939
17940 case DEBUGREFNPC:
17941 ri->guyref = vbound((value / 10000),0,255);
17942 break;
17943
17944
17945 //Game Over Screen
17946 case SETGAMEOVERELEMENT:
17947 {
17948 17 int32_t colour = value/10000;
17949 17 int32_t index = ri->d[rINDEX]/10000;
17950 17 index = vbound(index,0,SAVESC_LAST-1);
17951 17 SetSaveScreenSetting(index,colour);
17952 17 break;
17953 }
17954
17955 case SETGAMEOVERSTRING:
17956 {
17957 int32_t arrayptr = value/10000;
17958 int32_t index = ri->d[rINDEX]/10000;
17959 index = vbound(index,0,SAVESC_END-1);
17960 string filename_str;
17961 ArrayH::getString(arrayptr, filename_str, 73);
17962 ChangeSubscreenText(index,filename_str.c_str());
17963 break;
17964 }
17965
17966 ///----------------------------------------------------------------------------------------------------//
17967 //New Datatype Variables
17968
17969 ///----------------------------------------------------------------------------------------------------//
17970 //spritedata sp-> Variables
17971 case SPRITEDATATILE: SET_SPRITEDATA_VAR_INT(tile, "Tile"); break;
17972 case SPRITEDATAMISC: SET_SPRITEDATA_VAR_BYTE(misc, "Misc"); break;
17973 case SPRITEDATACSETS:
17974 {
17975 if(unsigned(ri->spritedataref) > (MAXWPNS-1) )
17976 {
17977 Z_scripterrlog("Invalid Sprite ID passed to spritedata->CSet: %d\n", (ri->spritedataref*10000));
17978 }
17979 else
17980 {
17981 wpnsbuf[ri->spritedataref].csets &= 0xF0;
17982 wpnsbuf[ri->spritedataref].csets |= vbound((value / 10000),0,15);
17983 }
17984 break;
17985 }
17986 case SPRITEDATAFLCSET:
17987 {
17988 if(unsigned(ri->spritedataref) > (MAXWPNS-1) )
17989 {
17990 Z_scripterrlog("Invalid Sprite ID passed to spritedata->FlashCSet: %d\n", (ri->spritedataref*10000));
17991 }
17992 else
17993 {
17994 wpnsbuf[ri->spritedataref].csets &= 0x0F;
17995 wpnsbuf[ri->spritedataref].csets |= vbound((value / 10000),0,15)<<4;
17996 }
17997 break;
17998 }
17999 case SPRITEDATAFRAMES: SET_SPRITEDATA_VAR_BYTE(frames, "Frames"); break;
18000 case SPRITEDATASPEED: SET_SPRITEDATA_VAR_BYTE(speed, "Speed"); break;
18001 case SPRITEDATATYPE: SET_SPRITEDATA_VAR_BYTE(type, "Type"); break;
18002 case SPRITEDATAFLAGS:
18003 {
18004 if(unsigned(ri->spritedataref) > (MAXWPNS-1) )
18005 {
18006 Z_scripterrlog("Invalid Sprite ID passed to spritedata->Flags[]: %d\n", (ri->spritedataref*10000));
18007 break;
18008 }
18009 int32_t index = ri->d[rINDEX]/10000;
18010 if(unsigned(index) >= 5)
18011 {
18012 Z_scripterrlog("Invalid index passed to spritedata->Flags[]: %d\n", index);
18013 break;
18014 }
18015 SETFLAG(wpnsbuf[ri->spritedataref].misc, 1<<index, value);
18016 break;
18017 }
18018
18019 ///----------------------------------------------------------------------------------------------------//
18020 //mapdata m-> Variables
18021 //mapdata m-> Variables
18022
18023 #define SET_MAPDATA_VAR_INT32(member) \
18024 { \
18025 if (mapscr *m = ResolveMapdata(ri->mapsref)) \
18026 { \
18027 m->member = vbound((value / 10000),-214747,214747); \
18028 } \
18029 break; \
18030 } \
18031
18032 #define SET_MAPDATA_VAR_INT16(member) \
18033 { \
18034 if (mapscr *m = ResolveMapdata(ri->mapsref)) \
18035 { \
18036 m->member = vbound((value / 10000),0,32767); \
18037 } \
18038 break; \
18039 } \
18040
18041 #define SET_MAPDATA_VAR_BYTE(member) \
18042 { \
18043 if (mapscr *m = ResolveMapdata(ri->mapsref)) \
18044 { \
18045 m->member = vbound((value / 10000),0,255); \
18046 } \
18047 break; \
18048 } \
18049
18050 #define SET_MAPDATA_VAR_INDEX32(member, indexbound) \
18051 { \
18052 int32_t indx = ri->d[rINDEX] / 10000; \
18053 if (BC::checkIndex(indx, 0, indexbound) != SH::_NoError) \
18054 { \
18055 } \
18056 else if (mapscr *m = ResolveMapdata(ri->mapsref)) \
18057 { \
18058 m->member[indx] = vbound((value / 10000),-214747,214747); \
18059 } \
18060 break; \
18061 } \
18062
18063 #define SET_MAPDATA_VAR_INDEX16(member, indexbound) \
18064 { \
18065 int32_t indx = ri->d[rINDEX] / 10000; \
18066 if (BC::checkIndex(indx, 0, indexbound) != SH::_NoError) \
18067 { \
18068 } \
18069 else if (mapscr *m = ResolveMapdata(ri->mapsref)) \
18070 { \
18071 m->member[indx] = vbound((value / 10000),-32767,32767); \
18072 } \
18073 break; \
18074 } \
18075
18076 #define SET_MAPDATA_BYTE_INDEX(member, indexbound) \
18077 { \
18078 int32_t indx = ri->d[rINDEX] / 10000; \
18079 if (BC::checkIndex(indx, 0, indexbound) != SH::_NoError) \
18080 { \
18081 } \
18082 else if (mapscr *m = ResolveMapdata(ri->mapsref)) \
18083 { \
18084 m->member[indx] = vbound((value / 10000),0,255); \
18085 } \
18086 break; \
18087 }\
18088
18089 #define SET_MAPDATA_LAYER_INDEX(member, indexbound) \
18090 { \
18091 int32_t indx = ri->d[rINDEX] / 10000; \
18092 if ( FFCore.quest_format[vFFScript] < 11 ) ++indx; \
18093 if (BC::checkIndex(indx, 1, indexbound) != SH::_NoError) \
18094 { \
18095 } \
18096 else if (mapscr *m = ResolveMapdata(ri->mapsref)) \
18097 { \
18098 m->member[indx-1] = vbound((value / 10000),0,255); \
18099 } \
18100 break; \
18101 } \
18102
18103 #define SET_MAPDATA_LAYERSCREEN_INDEX(member, indexbound) \
18104 { \
18105 int32_t indx = ri->d[rINDEX] / 10000; \
18106 if ( FFCore.quest_format[vFFScript] < 11 ) ++indx; \
18107 int32_t scrn_id = value/10000; \
18108 if (BC::checkIndex(indx, 1, indexbound) != SH::_NoError) \
18109 { \
18110 } \
18111 else if ( scrn_id > MAPSCRS ) \
18112 { \
18113 Z_scripterrlog("Script attempted to use a mapdata->LayerScreen[%d].\n",scrn_id); \
18114 Z_scripterrlog("Valid Screen values are (0) through (%d).\n",MAPSCRS); \
18115 } \
18116 else if (mapscr *m = ResolveMapdata(ri->mapsref)) \
18117 { \
18118 m->member[indx-1] = vbound((scrn_id),0,MAPSCRS); \
18119 } \
18120 break; \
18121 }\
18122
18123 #define SET_MAPDATA_BOOL_INDEX(member, indexbound) \
18124 { \
18125 int32_t indx = ri->d[rINDEX] / 10000; \
18126 if (BC::checkIndex(indx, 0, indexbound) != SH::_NoError) \
18127 { \
18128 } \
18129 else if (mapscr *m = ResolveMapdata(ri->mapsref)) \
18130 { \
18131 m->member[indx] =( (value/10000) ? 1 : 0 ); \
18132 } \
18133 break; \
18134 } \
18135
18136
18137 #define SET_FFC_MAPDATA_BOOL_INDEX(member, indexbound) \
18138 { \
18139 int32_t index = ri->d[rINDEX] / 10000; \
18140 if (auto handle = ResolveMapdataFFC(ri->mapsref, index)) \
18141 { \
18142 handle.ffc->member =( (value/10000) ? 1 : 0 ); \
18143 } \
18144 break; \
18145 } \
18146
18147 #define SET_MAPDATA_FLAG(member) \
18148 { \
18149 int32_t flag = (value/10000); \
18150 if (mapscr *m = ResolveMapdata(ri->mapsref)) \
18151 { \
18152 if ( flag != 0 ) \
18153 { \
18154 m->member|=flag; \
18155 } \
18156 else m->.member|= ~flag; \
18157 } \
18158 break; \
18159 } \
18160
18161 #define SET_MAPDATA_FFCPOS_INDEX32(member, indexbound) \
18162 { \
18163 int32_t index = (ri->d[rINDEX] / 10000); \
18164 if (auto handle = ResolveMapdataFFC(ri->mapsref, index)) \
18165 { \
18166 handle.ffc->member = zslongToFix(value); \
18167 } \
18168 break; \
18169 } \
18170
18171 #define SET_MAPDATA_FFC_INDEX32(member, indexbound) \
18172 { \
18173 int32_t index = (ri->d[rINDEX] / 10000); \
18174 if (auto handle = ResolveMapdataFFC(ri->mapsref, index)) \
18175 { \
18176 handle.ffc->member = value/10000; \
18177 } \
18178 break; \
18179 } \
18180
18181 #define SET_MAPDATA_FFC_INDEX_VBOUND(member, min, max) \
18182 { \
18183 int32_t v = value/10000; \
18184 int32_t index = (ri->d[rINDEX] / 10000); \
18185 if(v < min || v > max ) \
18186 { \
18187 scripting_log_error_with_context("Invalid value: {}", v); \
18188 } \
18189 else if (auto handle = ResolveMapdataFFC(ri->mapsref, index)) \
18190 { \
18191 handle.ffc->member = v; \
18192 } \
18193 break; \
18194 } \
18195
18196
1/2
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
114 case MAPDATAVALID: SET_MAPDATA_VAR_BYTE(valid); break; //b
18197 case MAPDATAGUY: SET_MAPDATA_VAR_BYTE(guy); break; //b
18198 case MAPDATASTRING: SET_MAPDATA_VAR_INT32(str); break; //w
18199 case MAPDATAROOM: SET_MAPDATA_VAR_BYTE(room); break; //b
18200 case MAPDATAITEM:
18201 {
18202 if (mapscr *m = ResolveMapdata(ri->mapsref))
18203 {
18204 auto v = vbound((value / 10000),-1,255);
18205 if(v > -1)
18206 m->item = v;
18207 m->hasitem = v > -1;
18208 }
18209 break;
18210 }
18211 case MAPDATAREGIONID:
18212 {
18213 370 int region_id = value / 10000;
18214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 370 times.
370 if (BC::checkBounds(region_id, 0, 9) != SH::_NoError)
18215 break;
18216
18217 370 auto result = decode_mapdata_ref(ri->mapsref);
18218
1/2
✓ Branch 0 taken 370 times.
✗ Branch 1 not taken.
370 if (result.scr)
18219 {
18220
1/2
✓ Branch 0 taken 370 times.
✗ Branch 1 not taken.
370 if (result.type == mapdata_type::CanonicalScreen)
18221 {
18222 370 Regions[result.scr->map].set_region_id(result.screen, region_id);
18223 370 }
18224 else
18225 {
18226 scripting_log_error_with_context("This may only be set for canonical screens");
18227 }
18228 370 }
18229 else
18230 {
18231 scripting_log_error_with_context("mapdata pointer is either invalid or uninitialised");
18232 }
18233 370 break;
18234 }
18235 case MAPDATAHASITEM: SET_MAPDATA_VAR_BYTE(hasitem); break; //b
18236 case MAPDATATILEWARPTYPE: SET_MAPDATA_BYTE_INDEX(tilewarptype, 3); break; //b, 4 of these
18237 //case MAPDATATILEWARPOVFLAGS: SET_MAPDATA_VAR_BYTE(tilewarpoverlayflags); break; //b, tilewarpoverlayflags
18238 case MAPDATADOORCOMBOSET: SET_MAPDATA_VAR_INT32(door_combo_set); break; //w
18239 case MAPDATAWARPRETX: SET_MAPDATA_BYTE_INDEX(warpreturnx, 3); break; //b, 4 of these
18240 case MAPDATAWARPRETY: SET_MAPDATA_BYTE_INDEX(warpreturny, 3); break; //b, 4 of these
18241 case MAPDATAWARPRETURNC: SET_MAPDATA_VAR_INT32(warpreturnc); break; //w
18242 case MAPDATASTAIRX: SET_MAPDATA_VAR_BYTE(stairx); break; //b
18243 case MAPDATASTAIRY: SET_MAPDATA_VAR_BYTE(stairy); break; //b
18244 case MAPDATAITEMX: SET_MAPDATA_VAR_BYTE(itemx); break; //itemx
18245 case MAPDATAITEMY: SET_MAPDATA_VAR_BYTE(itemy); break; //itemy
18246 case MAPDATACOLOUR: SET_MAPDATA_VAR_INT32(color); break; //w
18247 case MAPDATAENEMYFLAGS: SET_MAPDATA_VAR_BYTE(flags11); break; //b
18248 case MAPDATADOOR: SET_MAPDATA_BYTE_INDEX(door, 3); break; //b, 4 of these
18249 case MAPDATATILEWARPDMAP: SET_MAPDATA_VAR_INDEX32(tilewarpdmap, 3); break; //w, 4 of these
18250 case MAPDATATILEWARPSCREEN: SET_MAPDATA_BYTE_INDEX(tilewarpscr, 3); break; //b, 4 of these
18251 case MAPDATAEXITDIR: SET_MAPDATA_VAR_BYTE(exitdir); break; //b
18252 case MAPDATAENEMY:
18253 {
18254 int32_t indx = (ri->d[rINDEX] / 10000);
18255 int32_t enemyid = value/10000;
18256 if( ((unsigned)indx) > 9 )
18257 {
18258 Z_scripterrlog("Invalid Index passed to mapdata->%s: %d\n", "Enemy[]", (indx));
18259 }
18260 else if ( ((unsigned)enemyid) > MAXGUYS )
18261 {
18262 Z_scripterrlog("Invaid enemy ID (%d) passed to mapdata->%s.", enemyid,"Enemy[]");
18263 }
18264 else if (mapscr *m = ResolveMapdata(ri->mapsref))
18265 {
18266 m->enemy[indx] = enemyid;
18267 }
18268 break;
18269 }
18270 //case MAPDATAENEMY: SET_MAPDATA_VAR_INDEX32(enemy, "Enemy", 9); break; //w, 10 of these
18271 case MAPDATAPATTERN: SET_MAPDATA_VAR_BYTE(pattern); break; //b
18272 case MAPDATASIDEWARPTYPE: SET_MAPDATA_BYTE_INDEX(sidewarptype, 3); break; //b, 4 of these
18273 //case MAPDATASIDEWARPOVFLAGS: SET_MAPDATA_VAR_BYTE(sidewarpoverlayflags); break; //b
18274 case MAPDATAWARPARRIVALX: SET_MAPDATA_VAR_BYTE(warparrivalx); break; //b
18275 case MAPDATAWARPARRIVALY: SET_MAPDATA_VAR_BYTE(warparrivaly); break; //b
18276 case MAPDATAPATH: SET_MAPDATA_BYTE_INDEX(path, 3); break; //b, 4 of these
18277 case MAPDATASIDEWARPSC: SET_MAPDATA_BYTE_INDEX(sidewarpscr, 3); break; //b, 4 of these
18278 case MAPDATAINITDARRAY:
18279 {
18280 SET_MAPDATA_BYTE_INDEX(screeninitd, 7);
18281 break;
18282 }
18283
18284
18285 case MAPDATALAYERINVIS:
18286 {
18287 int32_t indx = ri->d[rINDEX] / 10000;
18288 if(indx < 0 || indx > 6 )
18289 {
18290 Z_scripterrlog("Invalid Index passed to mapdata->LayerInvisible[]: %d\n", indx);
18291 }
18292 else
18293 {
18294
18295 if (mapscr *m = ResolveMapdata(ri->mapsref))
18296 {
18297 if(value)
18298 {
18299 m->hidelayers |= (1<<indx);
18300 }
18301 else
18302 {
18303 m->hidelayers &= ~(1<<indx);
18304 }
18305 }
18306 }
18307 break;
18308 }
18309 case MAPDATASCRIPTDRAWS:
18310 {
18311 int32_t indx = ri->d[rINDEX] / 10000;
18312 if(indx < 0 || indx > 7 )
18313 {
18314 Z_scripterrlog("Invalid Index passed to mapdata->DisableScriptDraw[]: %d\n", indx);
18315 }
18316 else
18317 {
18318 if (mapscr *m = ResolveMapdata(ri->mapsref))
18319 {
18320 if(value)
18321 {
18322 m->hidescriptlayers &= ~(1<<indx);
18323 }
18324 else
18325 {
18326 m->hidescriptlayers |= (1<<indx);
18327 }
18328 }
18329 }
18330 break;
18331 }
18332
18333 case MAPDATATILEWARPOVFLAGS:
18334 {
18335 int32_t indx = ri->d[rINDEX] / 10000;
18336 if ( ((unsigned)indx) > 3 )
18337 {
18338 Z_scripterrlog("Invalid index passed to TileWarpOverlayFlags[%d].\n. Valid indices are [0] through [3].\n", indx);
18339 }
18340 else if (mapscr *m = ResolveMapdata(ri->mapsref))
18341 {
18342 if ( value ) m->tilewarpoverlayflags |= (1<<indx);
18343 else m->tilewarpoverlayflags &= ~(1<<indx);
18344 }
18345 break;
18346 }
18347
18348 case MAPDATASIDEWARPOVFLAGS:
18349 {
18350 int32_t indx = ri->d[rINDEX] / 10000;
18351 if ( ((unsigned)indx) > 3 )
18352 {
18353 Z_scripterrlog("Invalid index passed to SideWarpOverlayFlags[%d].\n. Valid indices are [0] through [3].\n", indx);
18354 }
18355 else if (mapscr *m = ResolveMapdata(ri->mapsref))
18356 {
18357 if ( value ) m->sidewarpoverlayflags |= (1<<indx);
18358 else m->sidewarpoverlayflags &= ~(1<<indx);
18359 }
18360 break;
18361 }
18362
18363 case MAPDATASIDEWARPDMAP: SET_MAPDATA_VAR_INDEX32(sidewarpdmap, 3); break; //w, 4 of these
18364 case MAPDATASIDEWARPINDEX: SET_MAPDATA_VAR_BYTE(sidewarpindex); break; //b
18365 case MAPDATAUNDERCOMBO: SET_MAPDATA_VAR_INT32(undercombo); break; //w
18366 case MAPDATAUNDERCSET: SET_MAPDATA_VAR_BYTE(undercset); break; //b
18367 case MAPDATACATCHALL: SET_MAPDATA_VAR_INT32(catchall); break; //W
18368
18369 case MAPDATACSENSITIVE: SET_MAPDATA_VAR_BYTE(csensitive); break; //B
18370 case MAPDATANORESET: SET_MAPDATA_VAR_INT32(noreset); break; //W
18371 case MAPDATANOCARRY: SET_MAPDATA_VAR_INT32(nocarry); break; //W
18372 //! Layer arrays should be a size of 7, and return the current screen / map / and OP_OPAQUE
18373 //! if you try to read 0, so that they correspond to actual layer IDs.
18374 //!
18375 case MAPDATALAYERMAP: SET_MAPDATA_LAYER_INDEX(layermap, 6); break; //B, 6 OF THESE
18376 case MAPDATALAYERSCREEN: SET_MAPDATA_LAYERSCREEN_INDEX(layerscreen, 6); break; //B, 6 OF THESE
18377 case MAPDATALAYEROPACITY: SET_MAPDATA_LAYER_INDEX(layeropacity, 6); break; //B, 6 OF THESE
18378 case MAPDATATIMEDWARPTICS: SET_MAPDATA_VAR_INT32(timedwarptics); break; //W
18379 case MAPDATANEXTMAP: SET_MAPDATA_VAR_BYTE(nextmap); break; //B
18380 case MAPDATANEXTSCREEN: SET_MAPDATA_VAR_BYTE(nextscr); break; //B
18381 case MAPDATASECRETCOMBO: SET_MAPDATA_VAR_INDEX32(secretcombo, 127); break; //W, 128 OF THESE
18382 case MAPDATASECRETCSET: SET_MAPDATA_BYTE_INDEX(secretcset, 127); break; //B, 128 OF THESE
18383 case MAPDATASECRETFLAG: SET_MAPDATA_BYTE_INDEX(secretflag, 127); break; //B, 128 OF THESE
18384 case MAPDATAVIEWX: break;//SET_MAPDATA_VAR_INT32(viewX, "ViewX"); break; //W
18385 case MAPDATASCRIPT:
18386 {
18387 auto result = decode_mapdata_ref(ri->mapsref);
18388 if (result.scr)
18389 {
18390 if (result.current())
18391 {
18392 if (get_qr(qr_CLEARINITDONSCRIPTCHANGE))
18393 {
18394 for (int q=0; q<8; q++)
18395 result.scr->screeninitd[q] = 0;
18396 }
18397
18398 on_reassign_script_engine_data(ScriptType::Screen, ri->screenref);
18399 }
18400
18401 result.scr->script = vbound(value/10000, 0, NUMSCRIPTSCREEN-1);
18402 }
18403 else
18404 {
18405 Z_scripterrlog("Script attempted to use a mapdata->%s on an invalid pointer\n","Script");
18406 }
18407 break;
18408 }
18409 case MAPDATAVIEWY: break;//SET_MAPDATA_VAR_INT32(viewY, "ViewY"); break; //W
18410 case MAPDATASCREENWIDTH: break;//SET_MAPDATA_VAR_BYTE(scrWidth, "Width"); break; //B
18411 case MAPDATASCREENHEIGHT: break;//SET_MAPDATA_VAR_BYTE(scrHeight, "Height"); break; //B
18412 case MAPDATAENTRYX: SET_MAPDATA_VAR_BYTE(entry_x); break; //B
18413 case MAPDATAENTRYY: SET_MAPDATA_VAR_BYTE(entry_y); break; //B
18414 case MAPDATAFFDATA:
18415 {
18416 int32_t index = (ri->d[rINDEX] / 10000);
18417
18418 if (auto handle = ResolveMapdataFFC(ri->mapsref, index))
18419 {
18420 zc_ffc_set(*handle.ffc, value/10000);
18421 }
18422 break; //W, MAXFFCS OF THESE
18423 }
18424 case MAPDATAFFCSET: SET_MAPDATA_FFC_INDEX32(cset, MAXFFCS-1); break; //B, MAXFFCS
18425 case MAPDATAFFDELAY: SET_MAPDATA_FFC_INDEX32(delay, MAXFFCS-1); break; //W, MAXFFCS
18426 case MAPDATAFFX: SET_MAPDATA_FFCPOS_INDEX32(x, MAXFFCS-1); break; //INT32, MAXFFCS OF THESE
18427 case MAPDATAFFY: SET_MAPDATA_FFCPOS_INDEX32(y, MAXFFCS-1); break; //..
18428 case MAPDATAFFXDELTA: SET_MAPDATA_FFCPOS_INDEX32(vx, MAXFFCS-1); break; //..
18429 case MAPDATAFFYDELTA: SET_MAPDATA_FFCPOS_INDEX32(vy, MAXFFCS-1); break; //..
18430 case MAPDATAFFXDELTA2: SET_MAPDATA_FFCPOS_INDEX32(ax, MAXFFCS-1); break; //..
18431 case MAPDATAFFYDELTA2: SET_MAPDATA_FFCPOS_INDEX32(ay, MAXFFCS-1); break; //..
18432
18433 case MAPDATAFFFLAGS:
18434 {
18435 int32_t index = (ri->d[rINDEX] / 10000);
18436
18437 if (auto handle = ResolveMapdataFFC(ri->mapsref, index))
18438 {
18439 handle.ffc->flags = (ffc_flags)(value/10000);
18440 handle.ffc->updateSolid();
18441 }
18442 break;
18443 }
18444
18445 //Number of ffcs that are in use (have valid data
18446 case MAPDATANUMFF:
18447 {
18448 break;
18449 }
18450
18451 case MAPDATASIDEWARPID:
18452 {
18453
18454 int32_t indx = ri->d[rINDEX] / 10000; //dir
18455 if (mapscr *m = ResolveMapdata(ri->mapsref); m && BC::checkBounds(indx, 0, 3) == BC::_NoError)
18456 {
18457 int32_t new_warp_return = vbound((value / 10000),-1,3); //none, A, B, C, D
18458 if(new_warp_return == -1)
18459 {
18460 m->flags2 &= ~(1<<indx); //Unset the "Enabled" flag for this dir
18461 m->sidewarpindex &= ~(3<<(2*indx)); //Clear the dir as well.
18462 }
18463 else
18464 {
18465 m->flags2 |= 1<<indx; //Set the "Enabled" flag for this dir
18466 m->sidewarpindex &= ~(3<<(2*indx)); //Clear the dir bits
18467 m->sidewarpindex |= (new_warp_return<<(2*indx)); //Set the new dir
18468 }
18469 }
18470 break;
18471 }
18472
18473 case MAPDATATWARPRETSQR:
18474 {
18475 int32_t indx = ri->d[rINDEX] / 10000;
18476 if ( ((unsigned)indx) > 3)
18477 {
18478 Z_scripterrlog("Invalid Array Index passed to mapdata->TileWarpReturnSquare[]: %d\n", indx);
18479 }
18480 else if (mapscr *m = ResolveMapdata(ri->mapsref))
18481 {
18482 int32_t wrindex = vbound(value/10000, 0, 3);
18483 m->warpreturnc = (m->warpreturnc&~(3<<(indx*2))) | (wrindex<<(indx*2));
18484 }
18485 break;
18486 }
18487
18488 //
18489 case MAPDATASWARPRETSQR:
18490 {
18491
18492 int32_t indx = ri->d[rINDEX] / 10000;
18493 if ( ((unsigned)indx) > 3)
18494 {
18495 Z_scripterrlog("Invalid Array Index passed to mapdata->SideWarpReturnSquare[]: %d\n", indx);
18496 }
18497 else if (mapscr *m = ResolveMapdata(ri->mapsref))
18498 {
18499 int32_t wrindex = vbound(value/10000, 0, 3);
18500 m->warpreturnc = (m->warpreturnc&~(3<<(8+(indx*2)))) | (wrindex<<(8+(indx*2)));
18501 }
18502 break;
18503 }
18504
18505 case MAPDATAFFWIDTH:
18506 {
18507 int32_t indx = (ri->d[rINDEX] / 10000)-1;
18508 if ( indx < 0 || indx > MAXFFCS-1 )
18509 {
18510 Z_scripterrlog("Invalid FFC Index passed to MapData->FFCTileWidth[]: %d\n", indx+1);
18511 }
18512 else if ( (value/10000) < 0 || (value/10000) > 4 )
18513 {
18514 Z_scripterrlog("Invalid WIDTH value passed to MapData->FFCTileWidth[]: %d\n", value/10000);
18515 }
18516 else if (mapscr *m = ResolveMapdata(ri->mapsref))
18517 {
18518 m->ffTileWidth(indx, (value/10000));
18519 }
18520 break;
18521 }
18522
18523 case MAPDATAFFHEIGHT:
18524 {
18525 int32_t indx = (ri->d[rINDEX] / 10000)-1;
18526 if ( indx < 0 || indx > MAXFFCS-1 )
18527 {
18528 Z_scripterrlog("Invalid FFC Index passed to MapData->FFCTileHeight[]: %d\n", indx+1);
18529 }
18530 else if ( (value/10000) < 0 || (value/10000) > 4 )
18531 {
18532 Z_scripterrlog("Invalid WIDTH value passed to MapData->FFCTileHeight[]: %d\n", value/10000);
18533 }
18534 else if (mapscr *m = ResolveMapdata(ri->mapsref))
18535 {
18536 m->ffTileHeight(indx, (value/10000));
18537 }
18538 break;
18539
18540 }
18541
18542 case MAPDATAFFEFFECTWIDTH:
18543 {
18544 int32_t indx = (ri->d[rINDEX] / 10000)-1;
18545 if ( indx < 0 || indx > MAXFFCS-1 )
18546 {
18547 Z_scripterrlog("Invalid FFC Index passed to MapData->FFCEffectWidth[]: %d\n", indx+1);
18548 }
18549 else if ( (value/10000) < 0 )
18550 {
18551 Z_scripterrlog("Invalid WIDTH value passed to MapData->FFCEffectWidth[]: %d\n", value/10000);
18552 }
18553 else if (mapscr *m = ResolveMapdata(ri->mapsref))
18554 {
18555 m->ffEffectWidth(indx, (value/10000));
18556 }
18557 break;
18558 }
18559
18560 case MAPDATAFFEFFECTHEIGHT:
18561 {
18562 int32_t indx = (ri->d[rINDEX] / 10000)-1;
18563 if ( indx < 0 || indx > MAXFFCS-1 )
18564 {
18565 Z_scripterrlog("Invalid FFC Index passed to MapData->FFCEffectHeight[]: %d\n", indx+1);
18566 }
18567 else if ( (value/10000) < 0 )
18568 {
18569 Z_scripterrlog("Invalid HEIGHT value passed to MapData->FFCEffectHeight[]: %d\n", value/10000);
18570 }
18571 else if (mapscr *m = ResolveMapdata(ri->mapsref))
18572 {
18573 m->ffEffectHeight(indx, (value/10000));
18574 }
18575 break;
18576 }
18577
18578 case MAPDATAFFLINK: SET_MAPDATA_FFC_INDEX_VBOUND(link, 0, MAXFFCS-1); break; //B, MAXFFCS OF THESE
18579 case MAPDATAFFSCRIPT: SET_MAPDATA_FFC_INDEX_VBOUND(script, 0, MAXFFCS-1); break; //W, 32 OF THESE
18580
18581 case MAPDATAINTID:
18582 {
18583 9 int32_t index = (ri->d[rINDEX]/10000);
18584 9 int32_t dindex = ri->d[rINDEX2]/10000;
18585
18586
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (BC::checkBounds(dindex, 0, 7) != SH::_NoError)
18587 break;
18588
18589
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (auto handle = ResolveMapdataFFC(ri->mapsref, index))
18590 9 handle.ffc->initd[dindex] = value;
18591 9 break;
18592 }
18593
18594
18595 //initd //INT32 , 32 OF THESE, EACH WITH 10 INDICES.
18596 case MAPDATAFFINITIALISED:
18597 {
18598 int32_t indx = ri->d[rINDEX] / 10000;
18599 if(indx < 0 || indx > MAXFFCS-1)
18600 {
18601 Z_scripterrlog("Invalid Index passed to mapdata->%s[]: %d\n", "FFCRunning", indx);
18602 }
18603 else if (mapscr *m = ResolveMapdata(ri->mapsref))
18604 {
18605 get_script_engine_data(ScriptType::FFC, indx).initialized = (value/10000) ? true : false;
18606 }
18607 }
18608 break;
18609
18610 case MAPDATASCRIPTENTRY:
18611 {
18612 Z_scripterrlog("Unimplemented: %s\n", "ScriptEntry");
18613 }
18614 break;
18615 case MAPDATASCRIPTOCCUPANCY:
18616 {
18617 Z_scripterrlog("Unimplemented: %s\n", "ScriptOccupancy");
18618 }
18619 break;
18620 case MAPDATASCRIPTEXIT:
18621 {
18622 Z_scripterrlog("Unimplemented: %s\n", "ExitScript");
18623 }
18624 break;
18625
18626 case MAPDATAOCEANSFX:
18627 {
18628 if (mapscr *m = ResolveMapdata(ri->mapsref))
18629 {
18630 int32_t v = vbound(value/10000, 0, 255);
18631 if(m == hero_scr && m->oceansfx != v)
18632 {
18633 stop_sfx(m->oceansfx);
18634 m->oceansfx = v;
18635 cont_sfx(m->oceansfx);
18636 }
18637 else m->oceansfx = v;
18638 }
18639 break;
18640 }
18641 case MAPDATABOSSSFX: SET_MAPDATA_VAR_BYTE(bosssfx); break; //B
18642 case MAPDATASECRETSFX: SET_MAPDATA_VAR_BYTE(secretsfx); break; //B
18643 case MAPDATAHOLDUPSFX: SET_MAPDATA_VAR_BYTE(holdupsfx); break; //B
18644 case MAPDATASCREENMIDI:
18645 {
18646 if (mapscr *m = ResolveMapdata(ri->mapsref))
18647 {
18648 m->screen_midi = vbound((value / 10000)-(MIDIOFFSET_MAPSCR-MIDIOFFSET_ZSCRIPT),-1,32767);
18649 }
18650 break;
18651 }
18652 case MAPDATALENSLAYER: SET_MAPDATA_VAR_BYTE(lens_layer); break; //B, OLD QUESTS ONLY?
18653
18654
18655 case MAPDATAFLAGS:
18656 {
18657 int32_t flagid = (ri->d[rINDEX])/10000;
18658 //bool valtrue = ( value ? 10000 : 0);
18659 if (mapscr *m = ResolveMapdata(ri->mapsref))
18660 {
18661 switch(flagid)
18662 {
18663 case 0: m->flags = (value / 10000); break;
18664 case 1: m->flags2 = (value / 10000); break;
18665 case 2: m->flags3 = (value / 10000); break;
18666 case 3: m->flags4 = (value / 10000); break;
18667 case 4: m->flags5 = (value / 10000); break;
18668 case 5: m->flags6 = (value / 10000); break;
18669 case 6: m->flags7 = (value / 10000); break;
18670 case 7: m->flags8 = (value / 10000); break;
18671 case 8: m->flags9 = (value / 10000); break;
18672 case 9: m->flags10 = (value / 10000); break;
18673 case 10: m->flags11 = (value / 10000); break;
18674 default:
18675 {
18676 Z_scripterrlog("Invalid index passed to mapdata->flags[]: %d\n", flagid);
18677 break;
18678 }
18679 }
18680 }
18681 break;
18682 }
18683
18684 case MAPDATAMISCD:
18685 {
18686 if(mapscr* m = ResolveMapdata(ri->mapsref))
18687 {
18688 int32_t indx = (ri->d[rINDEX])/10000;
18689 int32_t mi = get_mi(ri->mapsref);
18690 if(mi<0) break;
18691 if( ((unsigned)indx) > 7 )
18692 {
18693 Z_scripterrlog("You were trying to reference an out-of-bounds array index for a screen's D[] array (%ld); valid indices are from 0 to 7.\n", indx);
18694 break;
18695 }
18696 else
18697 {
18698 game->screen_d[mi][indx] = value/10000;
18699 break;
18700 }
18701 }
18702 break;
18703 }
18704
18705
18706 case MAPDATACOMBODD:
18707 {
18708 245580 int32_t val = (value/10000);
18709
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 245580 times.
245580 if ( ((unsigned) val) >= MAXCOMBOS )
18710 {
18711 Z_scripterrlog("Invalid combo ID %d used to write to mapdata->ComboD[]\n", val);
18712 break;
18713 }
18714
18715 245580 int pos = ri->d[rINDEX] / 10000;
18716 245580 auto result = decode_mapdata_ref(ri->mapsref);
18717
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 245580 times.
245580 if (auto rpos_handle = ResolveMapdataPos(ri->mapsref, pos))
18718 {
18719
2/2
✓ Branch 0 taken 61234 times.
✓ Branch 1 taken 184346 times.
245580 if (result.current())
18720 184346 screen_combo_modify_preroutine(rpos_handle);
18721 245580 rpos_handle.set_data(val);
18722
2/2
✓ Branch 0 taken 61234 times.
✓ Branch 1 taken 184346 times.
245580 if (result.current())
18723 184346 screen_combo_modify_postroutine(rpos_handle);
18724 245580 }
18725 }
18726 245580 break;
18727
18728 case MAPDATACOMBOCD:
18729 {
18730 154225 int32_t val = (value/10000); // cset
18731
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 154225 times.
154225 if ( ((unsigned) val) >= 15 )
18732 {
18733 Z_scripterrlog("Invalid CSet ID %d used to write to mapdata->ComboC[]\n", val);
18734 break;
18735 }
18736
18737 154225 int pos = ri->d[rINDEX] / 10000;
18738 154225 auto result = decode_mapdata_ref(ri->mapsref);
18739
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 154225 times.
154225 if (auto rpos_handle = ResolveMapdataPos(ri->mapsref, pos))
18740 {
18741
2/2
✓ Branch 0 taken 1786 times.
✓ Branch 1 taken 152439 times.
154225 if (result.current())
18742 152439 screen_combo_modify_preroutine(rpos_handle);
18743 154225 rpos_handle.set_cset(val&15);
18744
2/2
✓ Branch 0 taken 1786 times.
✓ Branch 1 taken 152439 times.
154225 if (result.current())
18745 152439 screen_combo_modify_postroutine(rpos_handle);
18746 154225 }
18747 }
18748 154225 break;
18749
18750 case MAPDATACOMBOFD:
18751 {
18752 56175 int32_t val = (value/10000); //flag
18753
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56175 times.
56175 if ( ((unsigned) val) >= 256 )
18754 {
18755 Z_scripterrlog("Invalid Flag ID %d used to write to mapdata->ComboF[]\n", val);
18756 break;
18757 }
18758
18759 56175 int pos = ri->d[rINDEX] / 10000;
18760
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56175 times.
56175 if (auto rpos_handle = ResolveMapdataPos(ri->mapsref, pos))
18761 {
18762 56175 rpos_handle.set_sflag(val);
18763 56175 }
18764 }
18765 56175 break;
18766
18767 case MAPDATACOMBOTD:
18768 {
18769 int32_t val = (value/10000); //type
18770 if ( ((unsigned) val) >= cMAX )
18771 {
18772 Z_scripterrlog("Invalid Type ID %d used to write to mapdata->ComboT[]\n", val);
18773 break;
18774 }
18775
18776 int pos = ri->d[rINDEX] / 10000;
18777 auto result = decode_mapdata_ref(ri->mapsref);
18778 if (auto rpos_handle = ResolveMapdataPos(ri->mapsref, pos))
18779 {
18780 auto cid = rpos_handle.data();
18781 if (result.current())
18782 screen_combo_modify_pre(cid);
18783 combobuf[cid].type=val;
18784 if (result.current())
18785 screen_combo_modify_post(cid);
18786 }
18787 }
18788 break;
18789
18790 case MAPDATACOMBOID:
18791 {
18792 int32_t val = (value/10000); //iflag
18793 if ( ((unsigned) val) >= 256 )
18794 {
18795 Z_scripterrlog("Invalid Flag ID %d used to write to mapdata->ComboI[]\n", val);
18796 break;
18797 }
18798
18799 int pos = ri->d[rINDEX] / 10000;
18800 if (auto rpos_handle = ResolveMapdataPos(ri->mapsref, pos))
18801 {
18802 rpos_handle.combo().flag = value/10000;
18803 }
18804 }
18805 break;
18806
18807 case MAPDATACOMBOSD:
18808 {
18809 int32_t val = (value/10000); //solidity
18810 if ( ((unsigned) val) >= 16 )
18811 {
18812 Z_scripterrlog("Invalid Solidity %d used to write to mapdata->ComboS[]\n", val);
18813 break;
18814 }
18815
18816 int pos = ri->d[rINDEX] / 10000;
18817 if (auto rpos_handle = ResolveMapdataPos(ri->mapsref, pos))
18818 {
18819 int32_t cid = rpos_handle.data();
18820 combobuf[cid].walk &= ~0x0F;
18821 combobuf[cid].walk |= (val)&0x0F;
18822 }
18823 }
18824 break;
18825
18826 case MAPDATACOMBOED:
18827 {
18828 int32_t val = (value/10000); //solidity
18829 if ( ((unsigned) val) >= 16 )
18830 {
18831 Z_scripterrlog("Invalid Solidity %d used to write to mapdata->ComboE[]\n", val);
18832 break;
18833 }
18834
18835 int pos = ri->d[rINDEX] / 10000;
18836 if (auto rpos_handle = ResolveMapdataPos(ri->mapsref, pos))
18837 {
18838 int32_t cid = rpos_handle.data();
18839 combobuf[cid].walk &= ~0xF0;
18840 combobuf[cid].walk |= ((val)&0x0F)<<4;
18841 }
18842 }
18843 break;
18844
18845 case MAPDATASCREENSTATED:
18846 {
18847 if(mapscr* m = ResolveMapdata(ri->mapsref))
18848 {
18849 int32_t mi = get_mi(ri->mapsref);
18850 if(mi<0) break;
18851 (value)?setmapflag_mi(mi, 1<<((ri->d[rINDEX])/10000)) : unsetmapflag_mi(mi, 1 << ((ri->d[rINDEX]) / 10000));
18852 }
18853 }
18854 break;
18855 case MAPDATAEXSTATED:
18856 {
18857 if(mapscr* m = ResolveMapdata(ri->mapsref))
18858 {
18859 int32_t mi = get_mi(ri->mapsref);
18860 if(mi<0) break;
18861 (value)?setxmapflag_mi(mi, 1<<((ri->d[rINDEX])/10000)) : unsetxmapflag_mi(mi, 1 << ((ri->d[rINDEX]) / 10000));
18862 }
18863 break;
18864 }
18865 case MAPDATALENSSHOWS:
18866 {
18867 int ind = ri->d[rINDEX]/10000;
18868 if(ind < 0 || ind > 6)
18869 Z_scripterrlog("Bad index mapdata->LensShows[%d]\n",ind);
18870 else if (mapscr *m = ResolveMapdata(ri->mapsref))
18871 {
18872 SETFLAG(m->lens_show, 1<<ind, value);
18873 if(value) m->lens_hide &= ~(1<<ind);
18874 }
18875 break;
18876 }
18877 case MAPDATALENSHIDES:
18878 {
18879 int ind = ri->d[rINDEX]/10000;
18880 if(ind < 0 || ind > 6)
18881 Z_scripterrlog("Bad index mapdata->LensHides[%d]\n",ind);
18882 else if (mapscr *m = ResolveMapdata(ri->mapsref))
18883 {
18884 SETFLAG(m->lens_hide, 1<<ind, value);
18885 if(value) m->lens_show &= ~(1<<ind);
18886 }
18887 break;
18888 }
18889 case MAPDATASCRDATASIZE:
18890 {
18891 if (mapscr *m = ResolveMapdata(ri->mapsref))
18892 {
18893 int index = get_ref_map_index(ri->mapsref);
18894 if (index < 0) break;
18895
18896 game->scriptDataResize(index, value/10000);
18897 }
18898 break;
18899 }
18900 case MAPDATASCRDATA:
18901 {
18902 if (mapscr *m = ResolveMapdata(ri->mapsref))
18903 {
18904 int mapindex = get_ref_map_index(ri->mapsref);
18905 if (mapindex < 0) break;
18906
18907 size_t indx = ri->d[rINDEX]/10000;
18908 if(indx >= game->scriptDataSize(mapindex))
18909 Z_scripterrlog("Invalid index passed to mapdata->Data[]: %d\n", indx);
18910 else game->screen_data[mapindex][indx] = value;
18911 }
18912 break;
18913 }
18914 case MAPDATAGUYCOUNT:
18915 {
18916 if (mapscr *m = ResolveMapdata(ri->mapsref))
18917 {
18918 int mi = get_mi(ri->mapsref);
18919 if(mi > -1)
18920 {
18921 game->guys[mi] = vbound(value/10000,10,0);
18922 break;
18923 }
18924 }
18925 break;
18926 }
18927 case MAPDATAEXDOOR:
18928 {
18929 if (mapscr *m = ResolveMapdata(ri->mapsref))
18930 {
18931 int mi = get_mi(ri->mapsref);
18932 if(mi < 0) break;
18933 int dir = SH::read_stack(ri->sp+1) / 10000;
18934 int ind = SH::read_stack(ri->sp+0) / 10000;
18935 if(unsigned(dir) > 3)
18936 Z_scripterrlog("Invalid dir '%d' passed to 'mapdata->SetExDoor()'; must be 0-3\n", dir);
18937 else if(unsigned(ind) > 7)
18938 Z_scripterrlog("Invalid index '%d' passed to 'mapdata->SetExDoor()'; must be 0-7\n", ind);
18939 else
18940 set_xdoorstate_mi(mi, dir, ind);
18941 }
18942 break;
18943 }
18944
18945 case MAPDATA_FLAG:
18946 {
18947 if (mapscr *scr = ResolveMapdata(ri->mapsref))
18948 {
18949 int32_t index = ri->d[rINDEX] / 10000;
18950 if (BC::checkIndex(index, 0, 8*11 - 1) != SH::_NoError)
18951 {
18952 break;
18953 }
18954
18955 byte& flag = (&scr->flags)[index/8];
18956 bool v = value;
18957 SETFLAG(flag, 1 << (index%8), v);
18958 }
18959 break;
18960 }
18961
18962
18963 ///----------------------------------------------------------------------------------------------------//
18964 //shopdata sd-> Variables
18965
18966 case SHOPDATAITEM:
18967 {
18968
18969 int32_t ref = ri->shopsref;
18970 bool isInfo = ( ref >= NUMSHOPS && ref <= NUMINFOSHOPS );
18971 int32_t indx = ri->d[rINDEX] / 10000;
18972 if ( indx < 0 || indx > 2 )
18973 {
18974 Z_scripterrlog("Invalid Array Index passed to shopdata->%s: %d\n", indx, "Item");
18975 break;
18976 }
18977 else
18978 {
18979 if ( isInfo )
18980 {
18981 Z_scripterrlog("Attempted to write an 'item' to an infoshop, using shop ID: %d\n", ri->shopsref);
18982 break;
18983 }
18984 else
18985 {
18986 QMisc.shop[ref].item[indx] = (byte)(vbound((value/10000), 0, 255));
18987 break;
18988 }
18989 }
18990 }
18991 break;
18992 //SET_SHOPDATA_VAR_INDEX(item, "Item", 2); break;
18993 case SHOPDATAHASITEM:
18994 {
18995
18996 int32_t ref = ri->shopsref;
18997 bool isInfo = ( ref >= NUMSHOPS && ref <= NUMINFOSHOPS );
18998 int32_t indx = ri->d[rINDEX] / 10000;
18999 if ( indx < 0 || indx > 2 )
19000 {
19001 Z_scripterrlog("Invalid Array Index passed to shopdata->%s: %d\n", indx, "HasItem");
19002 break;
19003 }
19004 else
19005 {
19006 if ( isInfo )
19007 {
19008 Z_scripterrlog("Attempted to write 'hasitem' to an infoshop, using shop ID: %d\n", ri->shopsref);
19009 break;
19010 }
19011 else
19012 {
19013 QMisc.shop[ref].hasitem[indx] = (byte)(vbound((value/10000), 0, 255)); break;
19014 }
19015 }
19016 }
19017 break;
19018 //SET_SHOPDATA_VAR_INDEX(hasitem, "HasItem", 2); break;
19019 case SHOPDATAPRICE:
19020 {
19021
19022 int32_t ref = ri->shopsref;
19023 bool isInfo = ( ref >= NUMSHOPS && ref <= NUMINFOSHOPS );
19024 int32_t indx = ri->d[rINDEX] / 10000;
19025 if ( indx < 0 || indx > 2 )
19026 {
19027 Z_scripterrlog("Invalid Array Index passed to shopdata->%s: %d\n", indx, "Price");
19028 break;
19029 }
19030 else
19031 {
19032 if ( isInfo )
19033 {
19034 QMisc.info[ref - NUMSHOPS].price[indx] = (word)(vbound((value/10000), 0, 65535));
19035 break;
19036 }
19037 else
19038 {
19039 QMisc.shop[ref].price[indx] = (word)(vbound((value/10000), 0, 65535));
19040 break;
19041 }
19042 }
19043 }
19044 //SET_SHOPDATA_VAR_INDEX(price, "Price", 2); break;
19045 //Pay for info
19046 case SHOPDATASTRING:
19047 {
19048 {
19049 int32_t ref = ri->shopsref;
19050 if ( ref < NUMSHOPS || ref > NUMINFOSHOPS )
19051 {
19052 Z_scripterrlog("Invalid Info Shop ID passed to shopdata->String[]: %d\n", ref);
19053 break;
19054 }
19055 else
19056 {
19057 bool isInfo = ( ref >= NUMSHOPS && ref <= NUMINFOSHOPS );
19058 int32_t indx = ri->d[rINDEX] / 10000;
19059 if ( indx < 0 || indx > 2 )
19060 {
19061 Z_scripterrlog("Invalid Array Index passed to shopdata->%s: %d\n", indx, "HasItem");
19062 break;
19063 }
19064 else
19065 {
19066 if ( isInfo )
19067 {
19068 QMisc.info[ref - NUMSHOPS].str[indx] = (word)(vbound((value/10000), 0, 32767));
19069 break;
19070 }
19071 else
19072 {
19073 QMisc.shop[ref].str[indx] = (word)(vbound((value/10000), 0, 32767));
19074 break;
19075 }
19076 }
19077
19078
19079 }
19080
19081 //GET_SHOPDATA_VAR_INDEX(str, String, 2); break;
19082 } break;
19083 }
19084
19085 ///----------------------------------------------------------------------------------------------------//
19086 //dmapdata dmd-> Variables
19087 case DMAPDATAMAP: //byte
19088 {
19089 DMaps[ri->dmapsref].map = ((byte)(value / 10000)) - 1; break;
19090 }
19091 case DMAPDATALEVEL: //word
19092 {
19093 DMaps[ri->dmapsref].level = ((word)(value / 10000)); break;
19094 }
19095 case DMAPDATAOFFSET: //char
19096 {
19097 DMaps[ri->dmapsref].xoff = ((char)(value / 10000)); break;
19098 }
19099 case DMAPDATACOMPASS: //byte
19100 {
19101 DMaps[ri->dmapsref].compass = ((byte)(value / 10000)); break;
19102 }
19103 case DMAPDATAPALETTE: //word
19104 {
19105 20 DMaps[ri->dmapsref].color= ((word)(value / 10000));
19106
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if(ri->dmapsref == cur_dmap)
19107 {
19108 10 loadlvlpal(DMaps[ri->dmapsref].color);
19109 10 currcset = DMaps[ri->dmapsref].color;
19110 10 }
19111 20 break;
19112 }
19113 case DMAPDATAMIDI: //byte
19114 {
19115 DMaps[ri->dmapsref].midi = ((byte)((value / 10000)+MIDIOFFSET_DMAP)); break;
19116 }
19117 case DMAPDATACONTINUE: //byte
19118 {
19119 DMaps[ri->dmapsref].cont = ((byte)(value / 10000)); break;
19120 }
19121 case DMAPDATATYPE: //byte
19122 {
19123 DMaps[ri->dmapsref].type = (((byte)(value / 10000))&dmfTYPE) | (DMaps[ri->dmapsref].type&~dmfTYPE); break;
19124 }
19125 case DMAPSCRIPT: //byte
19126 {
19127 DMaps[ri->dmapsref].script = vbound((value / 10000),0,NUMSCRIPTSDMAP-1);
19128 on_reassign_script_engine_data(ScriptType::DMap, ri->dmapsref);
19129 break;
19130 }
19131 case DMAPDATASIDEVIEW: //byte, treat as bool
19132 {
19133 DMaps[ri->dmapsref].sideview = ((value) ? 1 : 0); break;
19134 }
19135 case DMAPDATAGRID: //byte[8] --array
19136 {
19137 int32_t indx = ri->d[rINDEX] / 10000;
19138 if ( indx < 0 || indx > 7 )
19139 {
19140 scripting_log_error_with_context("Invalid index: {}", indx); break;
19141 }
19142 else
19143 {
19144 DMaps[ri->dmapsref].grid[indx] = ((byte)(value / 10000)); break;
19145 }
19146 }
19147 case DMAPINITD:
19148 {
19149 int32_t indx = ri->d[rINDEX] / 10000;
19150 if ( indx < 0 || indx > 7 )
19151 {
19152 scripting_log_error_with_context("Invalid index: {}", indx); break;
19153 }
19154 else
19155 {
19156 DMaps[ri->dmapsref].initD[indx] = value; break;
19157 }
19158 }
19159 case DMAPDATAMINIMAPTILE: //word - two of these, so let's do MinimapTile[2]
19160 {
19161 int32_t indx = ri->d[rINDEX] / 10000;
19162 switch(indx)
19163 {
19164 case 0: { DMaps[ri->dmapsref].minimap_1_tile = ((word)(value / 10000)); break; }
19165 case 1: { DMaps[ri->dmapsref].minimap_2_tile = ((word)(value / 10000)); break; }
19166 default:
19167 {
19168 scripting_log_error_with_context("Invalid index: {}", indx);
19169 break;
19170 }
19171 }
19172 break;
19173 }
19174 case DMAPDATAMINIMAPCSET: //byte - two of these, so let's do MinimapCSet[2]
19175 {
19176 int32_t indx = ri->d[rINDEX] / 10000;
19177 switch(indx)
19178 {
19179 case 0: { DMaps[ri->dmapsref].minimap_1_cset= ((byte)(value / 10000)); break; }
19180 case 1: { DMaps[ri->dmapsref].minimap_2_cset= ((byte)(value / 10000)); break; }
19181 default:
19182 {
19183 scripting_log_error_with_context("Invalid index: {}", indx);
19184 break;
19185 }
19186 }
19187 break;
19188 }
19189 case DMAPDATALARGEMAPTILE: //word -- two of these, so let's to LargemapTile[2]
19190 {
19191 int32_t indx = ri->d[rINDEX] / 10000;
19192 switch(indx)
19193 {
19194 case 0: { DMaps[ri->dmapsref].largemap_1_tile = ((word)(value / 10000)); break; }
19195 case 1: { DMaps[ri->dmapsref].largemap_2_tile = ((word)(value / 10000)); break; }
19196 default:
19197 {
19198 scripting_log_error_with_context("Invalid index: {}", indx);
19199 break;
19200 }
19201 }
19202 break;
19203 }
19204 case DMAPDATALARGEMAPCSET: //word -- two of these, so let's to LargemaCSet[2]
19205 {
19206 int32_t indx = ri->d[rINDEX] / 10000;
19207 switch(indx)
19208 {
19209 case 0: { DMaps[ri->dmapsref].largemap_1_cset= ((byte)(value / 10000)); break; }
19210 case 1: { DMaps[ri->dmapsref].largemap_2_cset= ((byte)(value / 10000)); break; }
19211 default:
19212 {
19213 scripting_log_error_with_context("Invalid index: {}", indx);
19214 break;
19215 }
19216 }
19217 break;
19218 }
19219 case DMAPDATAMUISCTRACK: //byte
19220 {
19221 DMaps[ri->dmapsref].tmusictrack= ((byte)(value / 10000)); break;
19222 }
19223 case DMAPDATASUBSCRA:
19224 {
19225 bool changed = DMaps[ri->dmapsref].active_subscreen != ((byte)(value / 10000));
19226 DMaps[ri->dmapsref].active_subscreen= ((byte)(value / 10000));
19227 if(changed&&ri->dmapsref==cur_dmap)
19228 update_subscreens();
19229 break;
19230 }
19231 case DMAPDATASUBSCRP:
19232 {
19233 5120 bool changed = DMaps[ri->dmapsref].passive_subscreen != ((byte)(value / 10000));
19234 5120 DMaps[ri->dmapsref].passive_subscreen= ((byte)(value / 10000));
19235
3/4
✓ Branch 0 taken 5120 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5110 times.
✓ Branch 3 taken 10 times.
5120 if(changed&&ri->dmapsref==cur_dmap)
19236 10 update_subscreens();
19237 5120 break;
19238 }
19239 case DMAPDATASUBSCRO:
19240 {
19241 bool changed = DMaps[ri->dmapsref].overlay_subscreen != ((byte)(value / 10000));
19242 DMaps[ri->dmapsref].overlay_subscreen = ((byte)(value / 10000));
19243 if(changed&&ri->dmapsref==cur_dmap)
19244 update_subscreens();
19245 break;
19246 }
19247 case DMAPDATADISABLEDITEMS: //byte[MAXITEMS]
19248 {
19249 int32_t indx = ri->d[rINDEX] / 10000;
19250 if ( indx < 0 || indx > (MAXITEMS-1) )
19251 {
19252 Z_scripterrlog("Invalid index supplied to dmapdata->Grid[]: %d\n", indx); break;
19253 }
19254 else
19255 {
19256 DMaps[ri->dmapsref].disableditems[indx] = ((byte)(value / 10000)); break;
19257 }
19258 }
19259
19260 case DMAPDATAFLAGARR: //int32_t
19261 {
19262 int32_t indx = ri->d[rINDEX] / 10000;
19263 if ( ((unsigned)indx) > 31 )
19264 {
19265 Z_scripterrlog("Invalid index supplied to dmapdata->Flags[]: %d\n", indx);
19266 break;
19267 }
19268 if ( value ) DMaps[ri->dmapsref].flags |= (1<<indx);
19269 else DMaps[ri->dmapsref].flags &= ~(1<<indx);
19270 break;
19271 }
19272 case DMAPDATAFLAGS: //int32_t
19273 {
19274 DMaps[ri->dmapsref].flags = (value / 10000); break;
19275 }
19276 case DMAPDATAMIRRDMAP:
19277 {
19278 DMaps[ri->dmapsref].mirrorDMap = vbound(value / 10000, -1, MAXDMAPS); break;
19279 }
19280 case DMAPDATALOOPSTART:
19281 {
19282 DMaps[ri->dmapsref].tmusic_loop_start = value;
19283 if (ri->dmapsref == cur_dmap)
19284 {
19285 if (FFCore.doing_dmap_enh_music(cur_dmap))
19286 {
19287 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
19288 }
19289 }
19290 break;
19291 }
19292 case DMAPDATALOOPEND:
19293 {
19294 DMaps[ri->dmapsref].tmusic_loop_end = value;
19295 if (ri->dmapsref == cur_dmap)
19296 {
19297 if (FFCore.doing_dmap_enh_music(cur_dmap))
19298 {
19299 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
19300 }
19301 }
19302 break;
19303 }
19304 case DMAPDATAXFADEIN:
19305 {
19306 DMaps[ri->dmapsref].tmusic_xfade_in = (value / 10000);
19307 break;
19308 }
19309 case DMAPDATAXFADEOUT:
19310 {
19311 DMaps[ri->dmapsref].tmusic_xfade_out = (value / 10000);
19312 if (DMaps[cur_dmap].tmusic[0]!=0 && strcmp(DMaps[ri->dmapsref].tmusic, zcmusic->filename) == 0)
19313 {
19314 zcmusic->fadeoutframes = (value / 10000);
19315 }
19316 break;
19317 }
19318 case DMAPDATAINTROSTRINGID:
19319 {
19320 DMaps[ri->dmapsref].intro_string_id = (value / 10000);
19321 break;
19322 }
19323 case MUSICUPDATECOND:
19324 {
19325 FFCore.music_update_cond = vbound(value / 10000, 0, 255);
19326 break;
19327 }
19328 case MUSICUPDATEFLAGS:
19329 {
19330 int32_t indx = ri->d[rINDEX] / 10000;
19331 if (indx < 0 || indx > 1)
19332 {
19333 scripting_log_error_with_context("Invalid index: {}", indx);
19334 break;
19335 }
19336 SETFLAG(FFCore.music_update_flags, 1 << indx, value);
19337 break;
19338 }
19339 case DMAPDATAASUBSCRIPT: //byte
19340 {
19341 DMaps[ri->dmapsref].active_sub_script = vbound((value / 10000),0,NUMSCRIPTSDMAP-1);
19342 on_reassign_script_engine_data(ScriptType::ScriptedActiveSubscreen, ri->dmapsref);
19343 break;
19344 }
19345 case DMAPDATAMAPSCRIPT: //byte
19346 {
19347 3225 DMaps[ri->dmapsref].onmap_script = vbound((value / 10000),0,NUMSCRIPTSDMAP-1);
19348 3225 on_reassign_script_engine_data(ScriptType::OnMap, ri->dmapsref);
19349 3225 break;
19350 }
19351 case DMAPDATAPSUBSCRIPT: //byte
19352 {
19353 FFScript::deallocateAllScriptOwned(ScriptType::ScriptedPassiveSubscreen, ri->dmapsref);
19354 word val = vbound((value / 10000),0,NUMSCRIPTSDMAP-1);
19355 if (FFCore.doscript(ScriptType::ScriptedPassiveSubscreen) && ri->dmapsref == cur_dmap && val == DMaps[ri->dmapsref].passive_sub_script)
19356 break;
19357 DMaps[ri->dmapsref].passive_sub_script = val;
19358 if(ri->dmapsref == cur_dmap)
19359 {
19360 FFCore.doscript(ScriptType::ScriptedPassiveSubscreen) = val != 0;
19361 };
19362 break;
19363 }
19364 case DMAPDATASUBINITD:
19365 {
19366 int32_t indx = ri->d[rINDEX] / 10000;
19367 if ( indx < 0 || indx > 7 )
19368 {
19369 scripting_log_error_with_context("Invalid index: {}", indx);
19370 }
19371 else
19372 {
19373 DMaps[ri->dmapsref].sub_initD[indx] = value; break;
19374 }
19375 }
19376
19377 case DMAPDATAMAPINITD:
19378 {
19379 int32_t indx = ri->d[rINDEX] / 10000;
19380 if ( indx < 0 || indx > 7 )
19381 {
19382 scripting_log_error_with_context("Invalid index: {}", indx);
19383 }
19384 else
19385 {
19386 DMaps[ri->dmapsref].onmap_initD[indx] = value; break;
19387 }
19388 }
19389
19390 case DMAPDATACHARTED:
19391 {
19392 int32_t screen = ri->d[rINDEX] / 10000;
19393 if(ri->dmapsref >= MAXDMAPS)
19394 {
19395 Z_scripterrlog("Invalid DMap reference used for dmapdata->Charted[]: %d\n", ri->dmapsref);
19396 }
19397 // else if((DMaps[get_currdmap()].type&dmfTYPE) == dmOVERW)
19398 // {
19399 // Z_scripterrlog("dmapdata->Charted[] cannot presently be used on Overworld-type dmaps\n");
19400 // }
19401 else if(((unsigned)(screen)) > 127)
19402 {
19403 scripting_log_error_with_context("Invalid screen: {}", screen);
19404 }
19405 else
19406 {
19407 int32_t col = (screen&15)-(DMaps[ri->dmapsref].type==dmOVERW ? 0 : DMaps[ri->dmapsref].xoff);
19408 if((DMaps[ri->dmapsref].type&dmfTYPE)!=dmOVERW ? (((unsigned)col) > 7) : (((unsigned)col) > 15))
19409 break; //Out-of-bounds; don't attempt write!
19410 int32_t di = (ri->dmapsref << 7) + (screen & 0x7F);
19411 game->bmaps[di] = (value/10000)&0x8F;
19412 }
19413 break;
19414 }
19415 //case DMAPDATAGRAVITY: //unimplemented
19416 //case DMAPDATAJUMPLAYER: //unimplemented
19417
19418 ///----------------------------------------------------------------------------------------------------//
19419 //messagedata msgd-> Variables
19420
19421
19422 case MESSAGEDATANEXT: //W
19423 {
19424 28 int32_t ID = ri->zmsgref;
19425
19426
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
28 if(BC::checkMessage(ID) != SH::_NoError)
19427 break;
19428 else
19429 28 MsgStrings[ID].nextstring = vbound((value/10000), 0, (msg_count-1));
19430 28 break;
19431 }
19432
19433 case MESSAGEDATATILE: //W
19434 {
19435 int32_t ID = ri->zmsgref;
19436
19437 if(BC::checkMessage(ID) != SH::_NoError)
19438 break;
19439 else
19440 MsgStrings[ID].tile = vbound((value/10000), 0, (NEWMAXTILES));
19441 break;
19442 }
19443
19444 case MESSAGEDATACSET: //b
19445 {
19446 int32_t ID = ri->zmsgref;
19447
19448 if(BC::checkMessage(ID) != SH::_NoError)
19449 break;
19450 else
19451 MsgStrings[ID].cset = ((byte)vbound((value/10000), 0, 15));
19452 break;
19453 }
19454 case MESSAGEDATATRANS: //BOOL
19455 {
19456 int32_t ID = ri->zmsgref;
19457
19458 if(BC::checkMessage(ID) != SH::_NoError)
19459 break;
19460 else
19461 (MsgStrings[ID].trans) = ((value)?true:false);
19462 break;
19463 }
19464 case MESSAGEDATAFONT: //B
19465 {
19466 int32_t ID = ri->zmsgref;
19467
19468 if(BC::checkMessage(ID) != SH::_NoError)
19469 break;
19470 else
19471 MsgStrings[ID].font = ((byte)vbound((value/10000), 0, 255));
19472 break;
19473 }
19474 case MESSAGEDATAX: //SHORT
19475 {
19476 24 int32_t ID = ri->zmsgref;
19477
19478
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(BC::checkMessage(ID) != SH::_NoError)
19479 break;
19480 else
19481 24 MsgStrings[ID].x = ((int16_t)vbound((value/10000), SHRT_MIN, SHRT_MAX));
19482 24 break;
19483 }
19484 case MESSAGEDATAY: //SHORT
19485 {
19486 24 int32_t ID = ri->zmsgref;
19487
19488
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(BC::checkMessage(ID) != SH::_NoError)
19489 break;
19490 else
19491 24 MsgStrings[ID].y = ((int16_t)vbound((value/10000), SHRT_MIN, SHRT_MAX));
19492 24 break;
19493 }
19494 case MESSAGEDATAW: //UNSIGNED SHORT
19495 {
19496 int32_t ID = ri->zmsgref;
19497
19498 if(BC::checkMessage(ID) != SH::_NoError)
19499 break;
19500 else
19501 MsgStrings[ID].w = ((uint16_t)vbound((value/10000), 0, USHRT_MAX));
19502 break;
19503 }
19504 case MESSAGEDATAH: //UNSIGNED SHORT
19505 {
19506 int32_t ID = ri->zmsgref;
19507
19508 if(BC::checkMessage(ID) != SH::_NoError)
19509 break;
19510 else
19511 MsgStrings[ID].h = ((uint16_t)vbound((value/10000), 0, USHRT_MAX));
19512 break;
19513 }
19514 case MESSAGEDATASFX: //BYTE
19515 {
19516 24 int32_t ID = ri->zmsgref;
19517
19518
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if(BC::checkMessage(ID) != SH::_NoError)
19519 break;
19520 else
19521 24 MsgStrings[ID].sfx = ((byte)vbound((value/10000), 0, 255));
19522 24 break;
19523 }
19524 case MESSAGEDATALISTPOS: //WORD
19525 {
19526 int32_t ID = ri->zmsgref;
19527
19528 if(BC::checkMessage(ID) != SH::_NoError)
19529 break;
19530 else
19531 MsgStrings[ID].listpos = vbound((value/10000), 1, (msg_count-1));
19532 break;
19533 }
19534 case MESSAGEDATAVSPACE: //BYTE
19535 {
19536 int32_t ID = ri->zmsgref;
19537
19538 if(BC::checkMessage(ID) != SH::_NoError)
19539 break;
19540 else
19541 MsgStrings[ID].vspace = ((byte)vbound((value/10000), 0, 255));
19542 break;
19543 }
19544 case MESSAGEDATAHSPACE: //BYTE
19545 {
19546 int32_t ID = ri->zmsgref;
19547
19548 if(BC::checkMessage(ID) != SH::_NoError)
19549 break;
19550 else
19551 MsgStrings[ID].hspace = ((byte)vbound((value/10000), 0, 255));
19552 break;
19553 }
19554 case MESSAGEDATAFLAGS: //BYTE
19555 {
19556 int32_t ID = ri->zmsgref;
19557
19558 if(BC::checkMessage(ID) != SH::_NoError)
19559 break;
19560 else
19561 MsgStrings[ID].stringflags = ((byte)vbound((value/10000), 0, 255));
19562 break;
19563 }
19564 case MESSAGEDATAMARGINS: //BYTE, 4
19565 {
19566 int32_t indx = ri->d[rINDEX] / 10000;
19567 if ( indx < 0 || indx > 3 )
19568 {
19569 Z_scripterrlog("Invalid index supplied to messagedata->Margins[]: %d\n", indx);
19570 break;
19571 }
19572 int32_t ID = ri->zmsgref;
19573
19574 if(BC::checkMessage(ID) != SH::_NoError)
19575 break;
19576 else
19577 MsgStrings[ID].margins[indx] = ((byte)vbound((value/10000), 0, 255));
19578 break;
19579 }
19580 case MESSAGEDATAPORTTILE: //INT
19581 {
19582 int32_t ID = ri->zmsgref;
19583
19584 if(BC::checkMessage(ID) != SH::_NoError)
19585 break;
19586 else
19587 MsgStrings[ID].portrait_tile = vbound((value/10000), 0, (NEWMAXTILES));
19588 break;
19589 }
19590 case MESSAGEDATAPORTCSET: //BYTE
19591 {
19592 int32_t ID = ri->zmsgref;
19593
19594 if(BC::checkMessage(ID) != SH::_NoError)
19595 break;
19596 else
19597 MsgStrings[ID].portrait_cset = ((byte)vbound((value/10000), 0, 15));
19598 break;
19599 }
19600 case MESSAGEDATAPORTX: //BYTE
19601 {
19602 int32_t ID = ri->zmsgref;
19603
19604 if(BC::checkMessage(ID) != SH::_NoError)
19605 break;
19606 else
19607 MsgStrings[ID].portrait_x = ((byte)vbound((value/10000), 0, 255));
19608 break;
19609 }
19610 case MESSAGEDATAPORTY: //BYTE
19611 {
19612 int32_t ID = ri->zmsgref;
19613
19614 if(BC::checkMessage(ID) != SH::_NoError)
19615 break;
19616 else
19617 MsgStrings[ID].portrait_y = ((byte)vbound((value/10000), 0, 255));
19618 break;
19619 }
19620 case MESSAGEDATAPORTWID: //BYTE
19621 {
19622 int32_t ID = ri->zmsgref;
19623
19624 if(BC::checkMessage(ID) != SH::_NoError)
19625 break;
19626 else
19627 MsgStrings[ID].portrait_tw = ((byte)vbound((value/10000), 0, 16));
19628 break;
19629 }
19630 case MESSAGEDATAPORTHEI: //BYTE
19631 {
19632 int32_t ID = ri->zmsgref;
19633
19634 if(BC::checkMessage(ID) != SH::_NoError)
19635 break;
19636 else
19637 MsgStrings[ID].portrait_th = ((byte)vbound((value/10000), 0, 14));
19638 break;
19639 }
19640 case MESSAGEDATAFLAGSARR: //BOOL, 7
19641 {
19642 int32_t indx = ri->d[rINDEX] / 10000;
19643 int32_t ID = ri->zmsgref;
19644
19645 if(BC::checkMessage(ID) != SH::_NoError)
19646 break;
19647 else
19648 {
19649 switch(indx)
19650 {
19651 case 0:
19652 (value) ? (MsgStrings[ID].stringflags)|=STRINGFLAG_WRAP : (MsgStrings[ID].stringflags)&= ~STRINGFLAG_WRAP;
19653 break;
19654 case 1:
19655 (value) ? (MsgStrings[ID].stringflags)|=STRINGFLAG_CONT : (MsgStrings[ID].stringflags)&= ~STRINGFLAG_CONT;
19656 break;
19657 case 2: //Not implemented
19658 //(value) ? (MsgStrings[ID].stringflags)|=STRINGFLAG_CENTER : (MsgStrings[ID].stringflags)&= ~STRINGFLAG_CENTER;
19659 break;
19660 case 3: //Not implemented
19661 //(value) ? (MsgStrings[ID].stringflags)|=STRINGFLAG_RIGHT : (MsgStrings[ID].stringflags)&= ~STRINGFLAG_RIGHT;
19662 break;
19663 case 4:
19664 (value) ? (MsgStrings[ID].stringflags)|=STRINGFLAG_FULLTILE : (MsgStrings[ID].stringflags)&= ~STRINGFLAG_FULLTILE;
19665 break;
19666 case 5:
19667 (value) ? (MsgStrings[ID].stringflags)|=STRINGFLAG_TRANS_BG : (MsgStrings[ID].stringflags)&= ~STRINGFLAG_TRANS_BG;
19668 break;
19669 case 6:
19670 (value) ? (MsgStrings[ID].stringflags)|=STRINGFLAG_TRANS_FG : (MsgStrings[ID].stringflags)&= ~STRINGFLAG_TRANS_FG;
19671 break;
19672 default:
19673 Z_scripterrlog("Invalid index supplied to messagedata->Flags[]: %d\n", indx);
19674 break;
19675 }
19676 }
19677 break;
19678 }
19679
19680
19681
19682
19683 ///----------------------------------------------------------------------------------------------------//
19684 //combodata cd-> Setter Variables
19685 //newcombo
19686 #define SET_COMBO_VAR_INT(member) \
19687 { \
19688 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
19689 { \
19690 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
19691 } \
19692 else \
19693 { \
19694 screen_combo_modify_pre(ri->combosref); \
19695 combobuf[ri->combosref].member = vbound((value / 10000),0,214747); \
19696 screen_combo_modify_post(ri->combosref); \
19697 \
19698 } \
19699 } \
19700
19701 #define SET_COMBO_VAR_DWORD(member) \
19702 { \
19703 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
19704 { \
19705 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
19706 } \
19707 else \
19708 { \
19709 screen_combo_modify_pre(ri->combosref); \
19710 combobuf[ri->combosref].member = vbound((value / 10000),0,32767); \
19711 screen_combo_modify_post(ri->combosref); \
19712 } \
19713 } \
19714
19715 #define SET_COMBO_VAR_BYTE(member) \
19716 { \
19717 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
19718 { \
19719 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
19720 } \
19721 else \
19722 { \
19723 screen_combo_modify_pre(ri->combosref); \
19724 combobuf[ri->combosref].member = vbound((value / 10000),0,255); \
19725 screen_combo_modify_post(ri->combosref); \
19726 } \
19727 } \
19728
19729 #define SET_COMBO_VAR_INDEX(member, indexbound) \
19730 { \
19731 int32_t indx = ri->d[rINDEX] / 10000; \
19732 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
19733 { \
19734 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
19735 } \
19736 else if ( indx < 0 || indx >= indexbound ) \
19737 { \
19738 scripting_log_error_with_context("Invalid Array Index: {}", indx); \
19739 } \
19740 else \
19741 { \
19742 screen_combo_modify_pre(ri->combosref); \
19743 combobuf[ri->combosref].member[indx] = vbound((value / 10000),0,214747); \
19744 screen_combo_modify_post(ri->combosref); \
19745 } \
19746 }
19747
19748 #define SET_COMBO_VAR_INDEX2(member, indexbound, low, high) \
19749 { \
19750 int32_t indx = ri->d[rINDEX] / 10000; \
19751 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
19752 { \
19753 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
19754 } \
19755 else if ( indx < 0 || indx >= indexbound ) \
19756 { \
19757 scripting_log_error_with_context("Invalid Array Index: {}", indx); \
19758 } \
19759 else \
19760 { \
19761 combobuf[ri->combosref].member[indx] = vbound((value / 10000),low,high); \
19762 } \
19763 }
19764
19765 #define SET_COMBO_BYTE_INDEX(member, indexbound) \
19766 { \
19767 int32_t indx = ri->d[rINDEX] / 10000; \
19768 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
19769 { \
19770 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
19771 } \
19772 else if ( indx < 0 || indx >= indexbound ) \
19773 { \
19774 scripting_log_error_with_context("Invalid Array Index: {}", indx); \
19775 } \
19776 else \
19777 { \
19778 combobuf[ri->combosref].member[indx] = vbound((value / 10000),0,255); \
19779 } \
19780 }
19781
19782 #define SET_COMBO_FLAG(member) \
19783 { \
19784 int32_t flag = (value/10000); \
19785 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
19786 { \
19787 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
19788 } \
19789 else \
19790 { \
19791 if ( flag != 0 ) \
19792 { \
19793 combobuf[ri->combosref].member|=flag; \
19794 } \
19795 else combobuf[ri->combosref].member|= ~flag; \
19796 } \
19797 } \
19798
19799 //comboclass
19800 #define SET_COMBOCLASS_VAR_INT(member) \
19801 { \
19802 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
19803 { \
19804 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
19805 } \
19806 else \
19807 { \
19808 combo_class_buf[combobuf[ri->combosref].type].member = vbound((value / 10000),0,214747); \
19809 } \
19810 } \
19811
19812 #define SET_COMBOCLASS_VAR_DWORD(member) \
19813 { \
19814 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
19815 { \
19816 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
19817 } \
19818 else \
19819 { \
19820 combo_class_buf[combobuf[ri->combosref].type].member = vbound((value / 10000),0,32767); \
19821 } \
19822 } \
19823
19824 #define SET_COMBOCLASS_VAR_BYTE(member) \
19825 { \
19826 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
19827 { \
19828 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
19829 } \
19830 else \
19831 { \
19832 combo_class_buf[combobuf[ri->combosref].type].member = vbound((value / 10000),0,255); \
19833 } \
19834 } \
19835
19836 #define SET_COMBOCLASS_VAR_INDEX(member, indexbound) \
19837 { \
19838 int32_t indx = ri->d[rINDEX] / 10000; \
19839 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
19840 { \
19841 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
19842 } \
19843 else if ( indx < 0 || indx > indexbound ) \
19844 { \
19845 scripting_log_error_with_context("Invalid Array Index: {}", indx); \
19846 } \
19847 else \
19848 { \
19849 combo_class_buf[combobuf[ri->combosref].type].member[indx] = vbound((value / 10000),0,214747); \
19850 } \
19851 }
19852
19853 #define SET_COMBOCLASS_BYTE_INDEX(member, indexbound) \
19854 { \
19855 int32_t indx = ri->d[rINDEX] / 10000; \
19856 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
19857 { \
19858 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
19859 } \
19860 else if ( indx < 0 || indx > indexbound ) \
19861 { \
19862 scripting_log_error_with_context("Invalid Array Index: {}", indx); \
19863 } \
19864 else \
19865 { \
19866 combo_class_buf[combobuf[ri->combosref].type].member[indx] = vbound((value / 10000),0,255); \
19867 } \
19868 }
19869
19870 #define SET_COMBOCLASS_FLAG(member, str) \
19871 { \
19872 int32_t flag = (value/10000); \
19873 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
19874 { \
19875 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
19876 } \
19877 else \
19878 { \
19879 if ( flag != 0 ) \
19880 { \
19881 combo_class_buf[combobuf[ri->combosref].type].member|=flag; \
19882 } \
19883 else combo_class_buf[combobuf[ri->combosref].type].member|= ~flag; \
19884 } \
19885 } \
19886
19887 //NEWCOMBO STRUCT
19888 case COMBODTILE: SET_COMBO_VAR_INT(tile); break; //word
19889 case COMBODOTILE:
19890 {
19891 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
19892 {
19893 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
19894 }
19895 else
19896 {
19897 newcombo& cdata = combobuf[ri->combosref];
19898 cdata.o_tile = vbound((value / 10000),0,NEWMAXTILES);
19899 if(get_qr(qr_NEW_COMBO_ANIMATION))
19900 {
19901 cdata.tile = cdata.o_tile + ((1+cdata.skipanim)*cdata.cur_frame);
19902 if(int32_t rowoffset = TILEROW(cdata.tile)-TILEROW(cdata.o_tile))
19903 {
19904 cdata.tile += cdata.skipanimy * rowoffset * TILES_PER_ROW;
19905 }
19906 combo_caches::drawing.refresh(ri->combosref);
19907 }
19908 }
19909 break;
19910 }
19911 case COMBODFRAME: SET_COMBO_VAR_BYTE(cur_frame); break; //char
19912 case COMBODACLK: SET_COMBO_VAR_BYTE(aclk); break; //char
19913 case COMBODATASCRIPT: SET_COMBO_VAR_DWORD(script); break; //word
19914 case COMBODASPEED: SET_COMBO_VAR_BYTE(speed); break; //char
19915 case COMBODFLIP: SET_COMBO_VAR_BYTE(flip); break; //char
19916 case COMBODWALK:
19917 {
19918 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
19919 {
19920 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
19921 }
19922 else
19923 {
19924 combobuf[ri->combosref].walk &= ~0x0F;
19925 combobuf[ri->combosref].walk |= (value / 10000)&0x0F;
19926 }
19927 break;
19928 }
19929 case COMBODEFFECT:
19930 {
19931 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
19932 {
19933 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
19934 }
19935 else
19936 {
19937 combobuf[ri->combosref].walk &= ~0xF0;
19938 combobuf[ri->combosref].walk |= ((value / 10000)&0x0F)<<4;
19939 }
19940 break;
19941 }
19942 case COMBODTYPE:
19943 {
19944 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
19945 {
19946 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
19947 }
19948 else
19949 {
19950 screen_combo_modify_pre(ri->combosref);
19951 combobuf[ri->combosref].type = vbound((value / 10000),0,255);
19952 screen_combo_modify_post(ri->combosref);
19953 }
19954 break;
19955 }
19956 case COMBODCSET:
19957 {
19958 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
19959 {
19960 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
19961 }
19962 else
19963 {
19964 screen_combo_modify_pre(ri->combosref);
19965 int8_t v = vbound(value, -8, 7);
19966 combobuf[ri->combosref].csets &= ~0xF;
19967 combobuf[ri->combosref].csets |= v;
19968 screen_combo_modify_post(ri->combosref);
19969 }
19970 break;
19971 }
19972 case COMBODCSET2FLAGS:
19973 {
19974 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
19975 {
19976 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
19977 }
19978 else
19979 {
19980 screen_combo_modify_pre(ri->combosref);
19981 combobuf[ri->combosref].csets &= 0xF;
19982 combobuf[ri->combosref].csets |= (value&0xF)<<4;
19983 screen_combo_modify_post(ri->combosref);
19984 }
19985 break;
19986 }
19987 case COMBODFOO: break; //W
19988 case COMBODFRAMES: SET_COMBO_VAR_BYTE(frames); break; //C
19989 case COMBODNEXTD: SET_COMBO_VAR_INT(nextcombo); break; //W
19990 case COMBODNEXTC: SET_COMBO_VAR_BYTE(nextcset); break; //C
19991 case COMBODFLAG: SET_COMBO_VAR_BYTE(flag); break; //C
19992 case COMBODSKIPANIM: SET_COMBO_VAR_BYTE(skipanim); break; //C
19993 case COMBODNEXTTIMER: SET_COMBO_VAR_DWORD(nexttimer); break; //W
19994 case COMBODAKIMANIMY: SET_COMBO_VAR_BYTE(skipanimy); break; //C
19995 case COMBODANIMFLAGS: SET_COMBO_VAR_BYTE(animflags); break; //C
19996 case COMBODEXPANSION: SET_COMBO_BYTE_INDEX(expansion, 6); break; //C , 6 INDICES
19997 case COMBODATTRIBUTES:
19998 {
19999 int32_t indx = ri->d[rINDEX] / 10000;
20000 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20001 {
20002 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20003 }
20004 else if ( indx < 0 || indx > 4 )
20005 {
20006 scripting_log_error_with_context("Invalid Array Index: {}", indx);
20007 }
20008 else
20009 {
20010 combobuf[ri->combosref].attributes[indx] = value;
20011 }
20012 }break;
20013 //case COMBODATAINITD: SET_COMBO_VAR_INDEX(initd, "InitD[]", 2); break; //LONG, 4 INDICES, INDIVIDUAL VALUES
20014 case COMBODATAINITD:
20015 {
20016 int32_t indx = ri->d[rINDEX] / 10000;
20017 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20018 {
20019 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20020 }
20021 else if ( ((unsigned)indx) > 8 )
20022 {
20023 scripting_log_error_with_context("Invalid Array Index: {}", indx);
20024 }
20025 else
20026 {
20027 combobuf[ri->combosref].initd[indx] = (value * ( get_qr(qr_COMBODATA_INITD_MULT_TENK) ? 10000 : 1));
20028 }
20029 break;
20030 }
20031
20032
20033 case COMBODATTRIBYTES: SET_COMBO_VAR_INDEX(attribytes, 8); break; //LONG, 4 INDICES, INDIVIDUAL VALUES
20034 case COMBODATTRISHORTS: SET_COMBO_VAR_INDEX2(attrishorts, 8, -32768, 32767); break; //LONG, 4 INDICES, INDIVIDUAL VALUES
20035 case COMBODUSRFLAGARR:
20036 {
20037 int32_t indx = ri->d[rINDEX] / 10000;
20038 if (ri->combosref < 0 || ri->combosref >(MAXCOMBOS - 1))
20039 {
20040 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20041 }
20042 else if (((unsigned)indx) > 15)
20043 {
20044 scripting_log_error_with_context("Invalid Array Index: {}", indx);
20045 }
20046 else
20047 {
20048 SETFLAG(combobuf[ri->combosref].usrflags, 1 << indx, value);
20049 }
20050 break;
20051 }
20052 case COMBODGENFLAGARR:
20053 {
20054 int32_t indx = ri->d[rINDEX] / 10000;
20055 if (ri->combosref < 0 || ri->combosref >(MAXCOMBOS - 1))
20056 {
20057 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20058 }
20059 else if (((unsigned)indx) > 0)
20060 {
20061 scripting_log_error_with_context("Invalid Array Index: {}", indx);
20062 }
20063 else
20064 {
20065 SETFLAG(combobuf[ri->combosref].genflags, 1 << indx, value);
20066 }
20067 break;
20068 }
20069 case COMBODUSRFLAGS: SET_COMBO_VAR_INT(usrflags); break; //LONG
20070 case COMBODTRIGGERFLAGS: SET_COMBO_VAR_INDEX(triggerflags, 6); break; //LONG 3 INDICES AS FLAGSETS
20071 case COMBODTRIGGERFLAGS2:
20072 {
20073 int32_t indx = ri->d[rINDEX] / 10000;
20074 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20075 {
20076 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20077 }
20078 else if ( unsigned(indx) >= 32*6 )
20079 {
20080 scripting_log_error_with_context("Invalid Array Index: {}", indx);
20081 }
20082 else
20083 {
20084 SETFLAG(combobuf[ri->combosref].triggerflags[indx/32],1<<(indx%32),value);
20085 }
20086 break;
20087 }
20088 case COMBODTRIGGERBUTTON:
20089 {
20090 int32_t indx = ri->d[rINDEX] / 10000;
20091 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20092 {
20093 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20094 }
20095 else if ( unsigned(indx) >= 8 )
20096 {
20097 scripting_log_error_with_context("Invalid Array Index: {}", indx);
20098 }
20099 else
20100 {
20101 SETFLAG(combobuf[ri->combosref].triggerbtn,1<<indx,value);
20102 }
20103 break;
20104 }
20105 case COMBODTRIGGERITEM:
20106 {
20107 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20108 {
20109 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20110 }
20111 else combobuf[ri->combosref].triggeritem = vbound(value/10000,0,255);
20112 break;
20113 }
20114 case COMBODTRIGGERTIMER:
20115 {
20116 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20117 {
20118 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20119 }
20120 else
20121 {
20122 screen_combo_modify_pre(ri->combosref);
20123 combobuf[ri->combosref].trigtimer = vbound(value/10000,0,255);
20124 screen_combo_modify_post(ri->combosref);
20125 }
20126 break;
20127 }
20128 case COMBODTRIGGERSFX:
20129 {
20130 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20131 {
20132 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20133 }
20134 else combobuf[ri->combosref].trigsfx = vbound(value/10000,0,255);
20135 break;
20136 }
20137 case COMBODTRIGGERCHANGECMB:
20138 {
20139 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20140 {
20141 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20142 }
20143 else combobuf[ri->combosref].trigchange = vbound(value/10000,-65535,65535);
20144 break;
20145 }
20146 case COMBODTRIGGERPROX:
20147 {
20148 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20149 {
20150 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20151 }
20152 else combobuf[ri->combosref].trigprox = vbound(value/10000,0,65535);
20153 break;
20154 }
20155 case COMBODTRIGGERLIGHTBEAM:
20156 {
20157 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20158 {
20159 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20160 }
20161 else combobuf[ri->combosref].triglbeam = vbound(value/10000,0,32);
20162 break;
20163 }
20164 case COMBODTRIGGERCTR:
20165 {
20166 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20167 {
20168 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20169 }
20170 else combobuf[ri->combosref].trigctr = vbound(value/10000, 0, MAX_COUNTERS-1);
20171 break;
20172 }
20173 case COMBODTRIGGERCTRAMNT:
20174 {
20175 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20176 {
20177 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20178 }
20179 else combobuf[ri->combosref].trigctramnt = vbound(value/10000, -65535, 65535);
20180 break;
20181 }
20182
20183 case COMBODTRIGGERCOOLDOWN:
20184 {
20185 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20186 {
20187 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20188 }
20189 else combobuf[ri->combosref].trigcooldown = vbound(value/10000, 0, 255);
20190 break;
20191 }
20192 case COMBODTRIGGERCOPYCAT:
20193 {
20194 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20195 {
20196 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20197 }
20198 else combobuf[ri->combosref].trigcopycat = vbound(value/10000, 0, 255);
20199 break;
20200 }
20201 case COMBODTRIGITEMPICKUP:
20202 {
20203 const int32_t allowed_pflags = ipHOLDUP | ipTIMER | ipSECRETS | ipCANGRAB;
20204 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20205 {
20206 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20207 }
20208 else combobuf[ri->combosref].spawnip = (value/10000)&allowed_pflags;
20209 break;
20210 }
20211 case COMBODTRIGEXSTATE:
20212 {
20213 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20214 {
20215 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20216 }
20217 else combobuf[ri->combosref].exstate = vbound(value/10000, -1, 31);
20218 break;
20219 }
20220 case COMBODTRIGEXDOORDIR:
20221 {
20222 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20223 {
20224 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20225 }
20226 else combobuf[ri->combosref].exdoor_dir = vbound(value/10000, -1, 3);
20227 break;
20228 }
20229 case COMBODTRIGEXDOORIND:
20230 {
20231 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20232 {
20233 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20234 }
20235 else combobuf[ri->combosref].exdoor_ind = vbound(value/10000, 0, 7);
20236 break;
20237 }
20238 case COMBODTRIGSPAWNENEMY:
20239 {
20240 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20241 {
20242 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20243 }
20244 else combobuf[ri->combosref].spawnenemy = vbound(value/10000, 0, 511);
20245 break;
20246 }
20247 case COMBODTRIGSPAWNITEM:
20248 {
20249 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20250 {
20251 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20252 }
20253 else combobuf[ri->combosref].spawnitem = vbound(value/10000, -255, 255);
20254 break;
20255 }
20256 case COMBODTRIGCSETCHANGE:
20257 {
20258 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20259 {
20260 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20261 }
20262 else combobuf[ri->combosref].trigcschange = vbound(value/10000, -15, 15);
20263 break;
20264 }
20265 case COMBODTRIGLITEMS:
20266 {
20267 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20268 {
20269 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20270 }
20271 else combobuf[ri->combosref].trig_levelitems = (value/10000)&liALL;
20272 break;
20273 }
20274 case COMBODTRIGDMAPLVL:
20275 {
20276 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20277 {
20278 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20279 }
20280 else combobuf[ri->combosref].trigdmlevel = vbound(value/10000, -1, MAXDMAPS-1);
20281 break;
20282 }
20283 case COMBODTRIGTINTR:
20284 {
20285 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20286 {
20287 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20288 }
20289 else combobuf[ri->combosref].trigtint[0] =
20290 scripting_write_pal_color(vbound(value/10000, -scripting_max_color_val, scripting_max_color_val));
20291 break;
20292 }
20293 case COMBODTRIGTINTG:
20294 {
20295 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20296 {
20297 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20298 }
20299 else combobuf[ri->combosref].trigtint[1] =
20300 scripting_write_pal_color(vbound(value/10000, -scripting_max_color_val, scripting_max_color_val));
20301 break;
20302 }
20303 case COMBODTRIGTINTB:
20304 {
20305 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20306 {
20307 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20308 }
20309 else combobuf[ri->combosref].trigtint[2] =
20310 scripting_write_pal_color(vbound(value/10000, -scripting_max_color_val, scripting_max_color_val));
20311 break;
20312 }
20313 case COMBODTRIGLVLPAL:
20314 {
20315 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20316 {
20317 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20318 }
20319 else combobuf[ri->combosref].triglvlpalette = vbound(value/10000, -1, 512);
20320 break;
20321 }
20322 case COMBODTRIGBOSSPAL:
20323 {
20324 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20325 {
20326 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20327 }
20328 else combobuf[ri->combosref].trigbosspalette = vbound(value/10000, -1, 29);
20329 break;
20330 }
20331 case COMBODTRIGQUAKETIME:
20332 {
20333 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20334 {
20335 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20336 }
20337 else combobuf[ri->combosref].trigquaketime = zc_max(value/10000, -1);
20338 break;
20339 }
20340 case COMBODTRIGWAVYTIME:
20341 {
20342 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20343 {
20344 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20345 }
20346 else combobuf[ri->combosref].trigwavytime = zc_max(value/10000, -1);
20347 break;
20348 }
20349 case COMBODTRIGSWORDJINX:
20350 {
20351 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20352 {
20353 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20354 }
20355 else combobuf[ri->combosref].trig_swjinxtime = zc_max(value/10000, -2);
20356 break;
20357 }
20358 case COMBODTRIGITEMJINX:
20359 {
20360 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20361 {
20362 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20363 }
20364 else combobuf[ri->combosref].trig_itmjinxtime = zc_max(value/10000, -2);
20365 break;
20366 }
20367 case COMBODTRIGSHIELDJINX:
20368 {
20369 if (ri->combosref < 0 || ri->combosref >(MAXCOMBOS - 1))
20370 {
20371 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20372 }
20373 else combobuf[ri->combosref].trig_shieldjinxtime = zc_max(value / 10000, -2);
20374 break;
20375 }
20376 case COMBODTRIGSTUN:
20377 {
20378 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20379 {
20380 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20381 }
20382 else combobuf[ri->combosref].trig_bunnytime = zc_max(value/10000, -2);
20383 break;
20384 }
20385 case COMBODTRIGBUNNY:
20386 {
20387 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20388 {
20389 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20390 }
20391 else combobuf[ri->combosref].trig_bunnytime = zc_max(value/10000, -2);
20392 break;
20393 }
20394 case COMBODTRIGPUSHTIME:
20395 {
20396 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20397 {
20398 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20399 }
20400 else combobuf[ri->combosref].trig_pushtime = vbound(value/10000, 0, 255);
20401 break;
20402 }
20403 case COMBODLIFTGFXCOMBO:
20404 {
20405 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20406 {
20407 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20408 }
20409 else combobuf[ri->combosref].liftcmb = vbound(value/10000, 0, MAXCOMBOS);
20410 break;
20411 }
20412 case COMBODLIFTGFXCCSET:
20413 {
20414 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20415 {
20416 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20417 }
20418 else combobuf[ri->combosref].liftcs = vbound(value/10000, 0, 13);
20419 break;
20420 }
20421 case COMBODLIFTUNDERCMB:
20422 {
20423 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20424 {
20425 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20426 }
20427 else combobuf[ri->combosref].liftundercmb = vbound(value/10000, 0, MAXCOMBOS);
20428 break;
20429 }
20430 case COMBODLIFTUNDERCS:
20431 {
20432 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20433 {
20434 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20435 }
20436 else combobuf[ri->combosref].liftundercs = vbound(value/10000, 0, 13);
20437 break;
20438 }
20439 case COMBODLIFTDAMAGE:
20440 {
20441 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20442 {
20443 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20444 }
20445 else combobuf[ri->combosref].liftdmg = vbound(value/10000, 0, 255);
20446 break;
20447 }
20448 case COMBODLIFTLEVEL:
20449 {
20450 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20451 {
20452 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20453 }
20454 else combobuf[ri->combosref].liftlvl = vbound(value/10000, 0, 255);
20455 break;
20456 }
20457 case COMBODLIFTITEM:
20458 {
20459 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20460 {
20461 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20462 }
20463 else combobuf[ri->combosref].liftitm = vbound(value/10000, 0, 255);
20464 break;
20465 }
20466 case COMBODLIFTFLAGS:
20467 {
20468 int32_t indx = ri->d[rINDEX] / 10000;
20469 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20470 {
20471 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20472 break;
20473 }
20474 if ( unsigned(indx) > 7 )
20475 {
20476 scripting_log_error_with_context("Invalid index: {}", indx);
20477 break;
20478 }
20479 SETFLAG(combobuf[ri->combosref].liftflags, (lift_flags)(1<<indx), value);
20480 break;
20481 }
20482 case COMBODLIFTGFXTYPE:
20483 {
20484 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20485 {
20486 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20487 }
20488 else combobuf[ri->combosref].liftgfx = vbound(value/10000, 0, 2);
20489 break;
20490 }
20491 case COMBODLIFTGFXSPRITE:
20492 {
20493 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20494 {
20495 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20496 }
20497 else combobuf[ri->combosref].liftsprite = vbound(value/10000, 0, 255);
20498 break;
20499 }
20500 case COMBODLIFTSFX:
20501 {
20502 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20503 {
20504 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20505 }
20506 else combobuf[ri->combosref].liftsfx = vbound(value/10000, 0, 255);
20507 break;
20508 }
20509 case COMBODLIFTBREAKSPRITE:
20510 {
20511 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20512 {
20513 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20514 }
20515 else combobuf[ri->combosref].liftbreaksprite = vbound(value/10000, -4, 255);
20516 break;
20517 }
20518 case COMBODLIFTBREAKSFX:
20519 {
20520 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20521 {
20522 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20523 }
20524 else combobuf[ri->combosref].liftbreaksfx = vbound(value/10000, 0, 255);
20525 break;
20526 }
20527 case COMBODLIFTHEIGHT:
20528 {
20529 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20530 {
20531 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20532 }
20533 else combobuf[ri->combosref].lifthei = vbound(value/10000, 0, 255);
20534 break;
20535 }
20536 case COMBODLIFTTIME:
20537 {
20538 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20539 {
20540 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20541 }
20542 else combobuf[ri->combosref].lifttime = vbound(value/10000, 0, 255);
20543 break;
20544 }
20545 case COMBODLIFTLIGHTRAD:
20546 {
20547 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20548 {
20549 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20550 }
20551 else combobuf[ri->combosref].liftlightrad = vbound(value/10000, 0, 255);
20552 break;
20553 }
20554 case COMBODLIFTLIGHTSHAPE:
20555 {
20556 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20557 {
20558 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20559 }
20560 else combobuf[ri->combosref].liftlightshape = vbound(value/10000, 0, 2);
20561 break;
20562 }
20563 case COMBODLIFTWEAPONITEM:
20564 {
20565 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20566 {
20567 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20568 }
20569 else combobuf[ri->combosref].lift_parent_item = vbound(value/10000, 0, 255);
20570 break;
20571 }
20572 case COMBODTRIGGERLSTATE:
20573 {
20574 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20575 {
20576 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20577 }
20578 else combobuf[ri->combosref].trig_lstate = vbound(value/10000, 0, 31);
20579 break;
20580 }
20581 case COMBODTRIGGERGSTATE:
20582 {
20583 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20584 {
20585 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20586 }
20587 else combobuf[ri->combosref].trig_gstate = vbound(value/10000, 0, 255);
20588 break;
20589 }
20590 case COMBODTRIGGERGROUP:
20591 {
20592 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20593 {
20594 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20595 }
20596 else combobuf[ri->combosref].trig_group = vbound(value/10000, 0, 255);
20597 break;
20598 }
20599 case COMBODTRIGGERGROUPVAL:
20600 {
20601 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20602 {
20603 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20604 }
20605 else combobuf[ri->combosref].trig_group_val = vbound(value/10000, 0, 65535);
20606 break;
20607 }
20608 case COMBODTRIGGERGTIMER:
20609 {
20610 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20611 {
20612 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20613 }
20614 else combobuf[ri->combosref].trig_statetime = vbound(value/10000, 0, 214748);
20615 break;
20616 }
20617 case COMBODTRIGGERGENSCRIPT:
20618 {
20619 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
20620 {
20621 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
20622 }
20623 else combobuf[ri->combosref].trig_genscr = vbound(value/10000, 0, 65535);
20624 break;
20625 }
20626 case COMBODTRIGGERLEVEL: SET_COMBO_VAR_INT(triggerlevel); break; //LONG
20627
20628
20629
20630
20631
20632 //COMBOCLASS STRUCT
20633 //case COMBODNAME: //CHAR[64], STRING
20634 case COMBODBLOCKNPC: SET_COMBOCLASS_VAR_BYTE(block_enemies); break; //C
20635 case COMBODBLOCKHOLE: SET_COMBOCLASS_VAR_BYTE(block_hole); break; //C
20636 case COMBODBLOCKTRIG: SET_COMBOCLASS_VAR_BYTE(block_trigger); break; //C
20637 case COMBODBLOCKWEAPON: SET_COMBOCLASS_BYTE_INDEX(block_weapon, 32); break; //C, 32 INDICES
20638 case COMBODCONVXSPEED: SET_COMBOCLASS_VAR_DWORD(conveyor_x_speed); break; //SHORT
20639 case COMBODCONVYSPEED: SET_COMBOCLASS_VAR_DWORD(conveyor_y_speed); break; //SHORT
20640 case COMBODSPAWNNPC: SET_COMBOCLASS_VAR_DWORD(create_enemy); break; //W
20641 case COMBODSPAWNNPCWHEN: SET_COMBOCLASS_VAR_BYTE(create_enemy_when); break; //C
20642 case COMBODSPAWNNPCCHANGE: SET_COMBOCLASS_VAR_INT(create_enemy_change); break; //LONG
20643 case COMBODDIRCHANGETYPE: SET_COMBOCLASS_VAR_BYTE(directional_change_type); break; //C
20644 case COMBODDISTANCECHANGETILES: SET_COMBOCLASS_VAR_INT(distance_change_tiles); break; //LONG
20645 case COMBODDIVEITEM: SET_COMBOCLASS_VAR_DWORD(dive_item); break; //SHORT
20646 case COMBODDOCK: SET_COMBOCLASS_VAR_BYTE(dock); break; //C
20647 case COMBODFAIRY: SET_COMBOCLASS_VAR_BYTE(fairy); break; //C
20648 case COMBODFFATTRCHANGE: SET_COMBOCLASS_VAR_BYTE(ff_combo_attr_change); break; //C
20649 case COMBODFOORDECOTILE: SET_COMBOCLASS_VAR_INT(foot_decorations_tile); break; //LONG
20650 case COMBODFOORDECOTYPE: SET_COMBOCLASS_VAR_BYTE(foot_decorations_type); break; //C
20651 case COMBODHOOKSHOTPOINT: SET_COMBOCLASS_VAR_BYTE(hookshot_grab_point); break; //C
20652 case COMBODLADDERPASS: SET_COMBOCLASS_VAR_BYTE(ladder_pass); break; //C
20653 case COMBODLOCKBLOCK: SET_COMBOCLASS_VAR_BYTE(lock_block_type); break; //C
20654 case COMBODLOCKBLOCKCHANGE: SET_COMBOCLASS_VAR_INT(lock_block_change); break; //LONG
20655 case COMBODMAGICMIRROR: SET_COMBOCLASS_VAR_BYTE(magic_mirror_type); break; //C
20656 case COMBODMODHPAMOUNT: SET_COMBOCLASS_VAR_DWORD(modify_hp_amount); break; //SHORT
20657 case COMBODMODHPDELAY: SET_COMBOCLASS_VAR_BYTE(modify_hp_delay); break; //C
20658 case COMBODMODHPTYPE: SET_COMBOCLASS_VAR_BYTE(modify_hp_type); break; //C
20659 case COMBODNMODMPAMOUNT: SET_COMBOCLASS_VAR_DWORD(modify_mp_amount); break; //SHORT
20660 case COMBODMODMPDELAY: SET_COMBOCLASS_VAR_BYTE(modify_mp_delay); break; //C
20661 case COMBODMODMPTYPE: SET_COMBOCLASS_VAR_BYTE(modify_mp_type); break; //C
20662 case COMBODNOPUSHBLOCK: SET_COMBOCLASS_VAR_BYTE(no_push_blocks); break; //C
20663 case COMBODOVERHEAD: SET_COMBOCLASS_VAR_BYTE(overhead); break; //C
20664 case COMBODPLACENPC: SET_COMBOCLASS_VAR_BYTE(place_enemy); break; //C
20665 case COMBODPUSHDIR: SET_COMBOCLASS_VAR_BYTE(push_direction); break; //C
20666 case COMBODPUSHWAIT: SET_COMBOCLASS_VAR_BYTE(push_wait); break; //C
20667 case COMBODPUSHHEAVY: SET_COMBOCLASS_VAR_BYTE(push_weight); break; //C
20668 case COMBODPUSHED: SET_COMBOCLASS_VAR_BYTE(pushed); break; //C
20669 case COMBODRAFT: SET_COMBOCLASS_VAR_BYTE(raft); break; //C
20670 case COMBODRESETROOM: SET_COMBOCLASS_VAR_BYTE(reset_room); break; //C
20671 case COMBODSAVEPOINTTYPE: SET_COMBOCLASS_VAR_BYTE(save_point_type); break; //C
20672 case COMBODSCREENFREEZETYPE: SET_COMBOCLASS_VAR_BYTE(screen_freeze_type); break; //C
20673 case COMBODSECRETCOMBO: SET_COMBOCLASS_VAR_BYTE(secret_combo); break; //C
20674 case COMBODSINGULAR: SET_COMBOCLASS_VAR_BYTE(singular); break; //C
20675 case COMBODSLOWWALK: SET_COMBOCLASS_VAR_BYTE(slow_movement); break; //C
20676 case COMBODSTATUETYPE: SET_COMBOCLASS_VAR_BYTE(statue_type); break; //C
20677 case COMBODSTEPTYPE: SET_COMBOCLASS_VAR_BYTE(step_type); break; //C
20678 case COMBODSTEPCHANGEINTO: SET_COMBOCLASS_VAR_INT(step_change_to); break; //LONG
20679 case COMBODSTRIKEWEAPONS: SET_COMBOCLASS_BYTE_INDEX(strike_weapons, 32); break; //BYTE, 32 INDICES.
20680 case COMBODSTRIKEREMNANTS: SET_COMBOCLASS_VAR_INT(strike_remnants); break; //LONG
20681 case COMBODSTRIKEREMNANTSTYPE: SET_COMBOCLASS_VAR_BYTE(strike_remnants_type); break; //C
20682 case COMBODSTRIKECHANGE: SET_COMBOCLASS_VAR_INT(strike_change); break; //LONG
20683 case COMBODSTRIKEITEM: SET_COMBOCLASS_VAR_DWORD(strike_item); break; //SHORT
20684 case COMBODTOUCHITEM: SET_COMBOCLASS_VAR_DWORD(touch_item); break; //SHORT
20685 case COMBODTOUCHSTAIRS: SET_COMBOCLASS_VAR_BYTE(touch_stairs); break; //C
20686 case COMBODTRIGGERTYPE: SET_COMBOCLASS_VAR_BYTE(trigger_type); break; //C
20687 case COMBODTRIGGERSENS: SET_COMBOCLASS_VAR_BYTE(trigger_sensitive); break; //C
20688 case COMBODWARPTYPE: SET_COMBOCLASS_VAR_BYTE(warp_type); break; //C
20689 case COMBODWARPSENS: SET_COMBOCLASS_VAR_BYTE(warp_sensitive); break; //C
20690 case COMBODWARPDIRECT: SET_COMBOCLASS_VAR_BYTE(warp_direct); break; //C
20691 case COMBODWARPLOCATION: SET_COMBOCLASS_VAR_BYTE(warp_location); break; //C
20692 case COMBODWATER: SET_COMBOCLASS_VAR_BYTE(water); break; //C
20693 case COMBODWHISTLE: SET_COMBOCLASS_VAR_BYTE(whistle); break; //C
20694 case COMBODWINGAME: SET_COMBOCLASS_VAR_BYTE(win_game); break; //C
20695 case COMBODBLOCKWPNLEVEL: SET_COMBOCLASS_VAR_BYTE(block_weapon_lvl); break; //C
20696
20697
20698
20699 ///----------------------------------------------------------------------------------------------------//
20700 //npcdata nd-> Variables
20701
20702 #define SET_NPCDATA_VAR_INT(member, str) \
20703 { \
20704 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
20705 { \
20706 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", (ri->npcdataref*10000), str); \
20707 } \
20708 else \
20709 { \
20710 guysbuf[ri->npcdataref].member = vbound((value / 10000),0,214747); \
20711 } \
20712 } \
20713
20714 #define SET_NPCDATA_VAR_DWORD(member, str) \
20715 { \
20716 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
20717 { \
20718 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", (ri->npcdataref*10000), str); \
20719 } \
20720 else \
20721 { \
20722 guysbuf[ri->npcdataref].member = vbound((value / 10000),0,32767); \
20723 } \
20724 } \
20725
20726 #define SET_NPCDATA_VAR_ENUM(member, str) \
20727 { \
20728 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
20729 { \
20730 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", (ri->npcdataref*10000), str); \
20731 } \
20732 else \
20733 { \
20734 guysbuf[ri->npcdataref].member = (decltype(guysbuf[ri->npcdataref].member))vbound((value / 10000),0,32767); \
20735 } \
20736 } \
20737
20738 #define SET_NPCDATA_VAR_BYTE(member, str) \
20739 { \
20740 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
20741 { \
20742 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", (ri->npcdataref*10000), str); \
20743 } \
20744 else \
20745 { \
20746 guysbuf[ri->npcdataref].member = vbound((value / 10000),0,255); \
20747 } \
20748 } \
20749
20750 #define SET_NPCDATA_VAR_INDEX(member, str, indexbound) \
20751 { \
20752 int32_t indx = ri->d[rINDEX] / 10000; \
20753 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
20754 { \
20755 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", (ri->npcdataref*10000), str); \
20756 } \
20757 else if ( (unsigned)indx > indexbound ) \
20758 { \
20759 Z_scripterrlog("Invalid Array Index passed to npcdata->%s: %d\n", indx, str); \
20760 } \
20761 else \
20762 { \
20763 guysbuf[ri->npcdataref].member[indx] = vbound((value / 10000),0,214747); \
20764 } \
20765 }
20766
20767 #define SET_NPCDATA_BYTE_INDEX(member, str, indexbound) \
20768 { \
20769 int32_t indx = ri->d[rINDEX] / 10000; \
20770 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
20771 { \
20772 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", (ri->npcdataref*10000), str); \
20773 } \
20774 else if ( (unsigned)indx > indexbound ) \
20775 { \
20776 Z_scripterrlog("Invalid Array Index passed to npcdata->%s: %d\n", indx, str); \
20777 } \
20778 else \
20779 { \
20780 guysbuf[ri->npcdataref].member[indx] = vbound((value / 10000),0,255); \
20781 } \
20782 }
20783
20784 #define SET_NPCDATA_FLAG(member, str) \
20785 { \
20786 int32_t flag = (value/10000); \
20787 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
20788 { \
20789 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", (ri->npcdataref*10000), str); \
20790 } \
20791 else \
20792 { \
20793 if ( flag ) \
20794 { \
20795 guysbuf[ri->npcdataref].member|=flag; \
20796 } \
20797 else guysbuf[ri->npcdataref].member|= ~flag; \
20798 } \
20799 } \
20800
20801 case NPCDATATILE: SET_NPCDATA_VAR_BYTE(tile, "Tile"); break;
20802 case NPCDATAWIDTH: SET_NPCDATA_VAR_BYTE(width, "Width"); break;
20803 case NPCDATAHEIGHT: SET_NPCDATA_VAR_BYTE(height, "Height"); break;
20804 case NPCDATAFLAGS1: SET_NPCDATA_VAR_ENUM(flags, "Flags (deprecated)"); break;
20805 case NPCDATAFLAGS2: SET_NPCDATA_VAR_ENUM(flags, "Flags2 (deprecated)"); break;
20806 case NPCDATASTILE: SET_NPCDATA_VAR_BYTE(s_tile, "STile"); break;
20807 case NPCDATASWIDTH: SET_NPCDATA_VAR_BYTE(s_width, "SWidth"); break;
20808 case NPCDATASHEIGHT: SET_NPCDATA_VAR_BYTE(s_height, "SHeight"); break;
20809 case NPCDATAETILE: SET_NPCDATA_VAR_INT(e_tile, "ExTile"); break;
20810 case NPCDATAEWIDTH: SET_NPCDATA_VAR_BYTE(e_width, "ExWidth"); break;
20811 case NPCDATASCRIPT: SET_NPCDATA_VAR_BYTE(script, "Script"); break;
20812 case NPCDATAEHEIGHT: SET_NPCDATA_VAR_BYTE(e_height, "ExHeight"); break;
20813 case NPCDATAHP: SET_NPCDATA_VAR_DWORD(hp, "HP"); break;
20814 case NPCDATAFAMILY: SET_NPCDATA_VAR_DWORD(family, "Family"); break;
20815 case NPCDATACSET: SET_NPCDATA_VAR_DWORD(cset, "CSet"); break;
20816 case NPCDATAANIM: SET_NPCDATA_VAR_DWORD(anim, "Anim"); break;
20817 case NPCDATAEANIM: SET_NPCDATA_VAR_DWORD(e_anim, "ExAnim"); break;
20818 case NPCDATAFRAMERATE: SET_NPCDATA_VAR_DWORD(frate, "Framerate"); break;
20819 case NPCDATAEFRAMERATE: SET_NPCDATA_VAR_DWORD(e_frate, "ExFramerate"); break;
20820 case NPCDATATOUCHDAMAGE: SET_NPCDATA_VAR_DWORD(dp, "TouchDamage"); break;
20821 case NPCDATAWEAPONDAMAGE: SET_NPCDATA_VAR_DWORD(wdp, "WeaponDamage"); break;
20822 case NPCDATAWEAPON: SET_NPCDATA_VAR_DWORD(weapon, "Weapon"); break;
20823 case NPCDATARANDOM: SET_NPCDATA_VAR_DWORD(rate, "Random"); break;
20824 case NPCDATAHALT: SET_NPCDATA_VAR_DWORD(hrate, "Haltrate"); break;
20825 case NPCDATASTEP: SET_NPCDATA_VAR_DWORD(step, "Step"); break;
20826 case NPCDATAHOMING: SET_NPCDATA_VAR_DWORD(homing, "Homing"); break;
20827 case NPCDATAHUNGER: SET_NPCDATA_VAR_DWORD(grumble, "Hunger"); break;
20828 case NPCDATADROPSET: SET_NPCDATA_VAR_DWORD(item_set, "Dropset"); break;
20829 case NPCDATABGSFX: SET_NPCDATA_VAR_DWORD(bgsfx, "BGSFX"); break;
20830 case NPCDATADEATHSFX: SET_NPCDATA_VAR_BYTE(deadsfx, "DeathSFX"); break;
20831 case NPCDATAHITSFX: SET_NPCDATA_VAR_BYTE(hitsfx, "HitSFX"); break;
20832 case NPCDATAXOFS: SET_NPCDATA_VAR_INT(xofs, "DrawXOffset"); break;
20833 case NPCDATAYOFS: SET_NPCDATA_VAR_INT(yofs, "DrawYOffset"); break;
20834 case NPCDATAZOFS: SET_NPCDATA_VAR_INT(zofs, "DrawZOffset"); break;
20835 case NPCDATAHXOFS: SET_NPCDATA_VAR_INT(hxofs, "HitXOffset"); break;
20836 case NPCDATAHYOFS: SET_NPCDATA_VAR_INT(hyofs, "HitYOffset"); break;
20837 case NPCDATAHITWIDTH: SET_NPCDATA_VAR_INT(hxsz, "HitWidth"); break;
20838 case NPCDATAHITHEIGHT: SET_NPCDATA_VAR_INT(hysz, "HitHeight"); break;
20839 case NPCDATAHITZ: SET_NPCDATA_VAR_INT(hzsz, "HitZHeight"); break;
20840 case NPCDATATILEWIDTH: SET_NPCDATA_VAR_INT(txsz, "TileWidth"); break;
20841 case NPCDATATILEHEIGHT: SET_NPCDATA_VAR_INT(tysz, "TileHeight"); break;
20842 case NPCDATAWPNSPRITE: SET_NPCDATA_VAR_INT(wpnsprite, "WeaponSprite"); break;
20843 case NPCDATAWEAPONSCRIPT: SET_NPCDATA_VAR_INT(weaponscript, "WeaponScript"); break;
20844 case NPCDATADEFENSE: SET_NPCDATA_VAR_INDEX(defense, "Defense", 42); break;
20845 case NPCDATAWEAPONINITD: SET_NPCDATA_VAR_INDEX(weap_initiald, "WeaponInitD", 8); break;
20846 case NPCDATAINITD: SET_NPCDATA_VAR_INDEX(initD, "InitD", 8); break;
20847 case NPCDATASIZEFLAG: SET_NPCDATA_VAR_INT(SIZEflags, "SizeFlags"); break;
20848
20849 case NPCDATAFROZENTILE: SET_NPCDATA_VAR_INT(frozentile, "FrozenTile"); break;
20850 case NPCDATAFROZENCSET: SET_NPCDATA_VAR_INT(frozencset, "FrozenCSet"); break;
20851 case NPCDATAFIRESFX: SET_NPCDATA_VAR_BYTE(firesfx, "WeaponSFX"); break;
20852 case NPCDATAATTRIBUTE:
20853 {
20854 int32_t indx = ri->d[rINDEX] / 10000;
20855 if(ri->npcdataref > (MAXNPCS-1) )
20856 {
20857 Z_scripterrlog("Invalid Sprite ID passed to npcdata->Attributes[]: %d\n", (ri->npcdataref*10000));
20858 }
20859 else if ( indx < 0 || indx >= MAX_NPC_ATTRIBUTES )
20860 {
20861 Z_scripterrlog("Invalid Array Index passed to npcdata->Attributes[]: %d\n", indx);
20862 }
20863 else
20864 {
20865 guysbuf[ri->npcdataref].attributes[indx] = (value / 10000);
20866 }
20867 break;
20868 }
20869
20870 case NPCDATAFLAG:
20871 {
20872 int32_t indx = ri->d[rINDEX] / 10000;
20873 if(ri->npcdataref > (MAXNPCS-1) )
20874 {
20875 Z_scripterrlog("Invalid Sprite ID passed to npcdata->Flags[]: %d\n", (ri->npcdataref*10000));
20876 }
20877 else if ( indx < 0 || indx >= MAX_NPC_FLAGS )
20878 {
20879 Z_scripterrlog("Invalid Array Index passed to npcdata->Flags[]: %d\n", indx);
20880 }
20881 else
20882 {
20883 guy_flags bit = (guy_flags)(1<<indx);
20884 if(value)
20885 guysbuf[ri->npcdataref].flags |= bit;
20886 else
20887 guysbuf[ri->npcdataref].flags &= ~bit;
20888 }
20889 break;
20890 }
20891
20892 case NPCDATABEHAVIOUR:
20893 {
20894 if(ri->npcdataref > (MAXNPCS-1) )
20895 {
20896 break;
20897 }
20898
20899
20900 int32_t index = vbound(ri->d[rINDEX]/10000,0,4);
20901 switch(index){
20902 case 0:
20903 (value) ? guysbuf[ri->npcdataref].editorflags|=ENEMY_FLAG1 : guysbuf[ri->npcdataref].editorflags&= ~ENEMY_FLAG1;
20904 break;
20905 case 1:
20906 (value) ? guysbuf[ri->npcdataref].editorflags|=ENEMY_FLAG2 : guysbuf[ri->npcdataref].editorflags&= ~ENEMY_FLAG2;
20907 break;
20908 case 2:
20909 (value) ? guysbuf[ri->npcdataref].editorflags|=ENEMY_FLAG3 : guysbuf[ri->npcdataref].editorflags&= ~ENEMY_FLAG3;
20910 break;
20911 case 3:
20912 (value) ? guysbuf[ri->npcdataref].editorflags|=ENEMY_FLAG4 : guysbuf[ri->npcdataref].editorflags&= ~ENEMY_FLAG4;
20913 break;
20914 case 4:
20915 (value) ? guysbuf[ri->npcdataref].editorflags|=ENEMY_FLAG5 : guysbuf[ri->npcdataref].editorflags&= ~ENEMY_FLAG5;
20916 break;
20917 case 5:
20918 (value) ? guysbuf[ri->npcdataref].editorflags|=ENEMY_FLAG6 : guysbuf[ri->npcdataref].editorflags&= ~ENEMY_FLAG6;
20919 break;
20920 case 6:
20921 (value) ? guysbuf[ri->npcdataref].editorflags|=ENEMY_FLAG7 : guysbuf[ri->npcdataref].editorflags&= ~ENEMY_FLAG7;
20922 break;
20923 case 7:
20924 (value) ? guysbuf[ri->npcdataref].editorflags|=ENEMY_FLAG8 : guysbuf[ri->npcdataref].editorflags&= ~ENEMY_FLAG8;
20925 break;
20926 case 8:
20927 (value) ? guysbuf[ri->npcdataref].editorflags|=ENEMY_FLAG9 : guysbuf[ri->npcdataref].editorflags&= ~ENEMY_FLAG9;
20928 break;
20929 case 9:
20930 (value) ? guysbuf[ri->npcdataref].editorflags|=ENEMY_FLAG10 : guysbuf[ri->npcdataref].editorflags&= ~ENEMY_FLAG10;
20931 break;
20932 case 10:
20933 (value) ? guysbuf[ri->npcdataref].editorflags|=ENEMY_FLAG11 : guysbuf[ri->npcdataref].editorflags&= ~ENEMY_FLAG11;
20934 break;
20935 case 11:
20936 (value) ? guysbuf[ri->npcdataref].editorflags|=ENEMY_FLAG12 : guysbuf[ri->npcdataref].editorflags&= ~ENEMY_FLAG12;
20937 break;
20938 case 12:
20939 (value) ? guysbuf[ri->npcdataref].editorflags|=ENEMY_FLAG13 : guysbuf[ri->npcdataref].editorflags&= ~ENEMY_FLAG13;
20940 break;
20941 case 13:
20942 (value) ? guysbuf[ri->npcdataref].editorflags|=ENEMY_FLAG14 : guysbuf[ri->npcdataref].editorflags&= ~ENEMY_FLAG14;
20943 break;
20944 case 14:
20945 (value) ? guysbuf[ri->npcdataref].editorflags|=ENEMY_FLAG15 : guysbuf[ri->npcdataref].editorflags&= ~ENEMY_FLAG15;
20946 break;
20947 case 15:
20948 (value) ? guysbuf[ri->npcdataref].editorflags|=ENEMY_FLAG16 : guysbuf[ri->npcdataref].editorflags&= ~ENEMY_FLAG16;
20949 break;
20950
20951
20952 default:
20953 break;
20954 }
20955
20956 break;
20957 }
20958
20959 case NPCDATASHIELD:
20960 {
20961 int32_t indx = ri->d[rINDEX] / 10000;
20962 if(ri->npcdataref > (MAXNPCS-1) )
20963 {
20964 Z_scripterrlog("Invalid NPC ID passed to npcdata->Shield[]: %d\n", (ri->npcdataref*10000));
20965 break;
20966 }
20967 else
20968 {
20969 switch(indx)
20970 {
20971 case 0:
20972 {
20973 (ri->d[rINDEX2])? (guysbuf[ri->npcdataref].flags |= guy_shield_front) : (guysbuf[ri->npcdataref].flags &= ~guy_shield_front);
20974 break;
20975 }
20976 case 1:
20977 {
20978 (ri->d[rINDEX2])? (guysbuf[ri->npcdataref].flags |= guy_shield_left) : (guysbuf[ri->npcdataref].flags &= ~guy_shield_left);
20979 break;
20980 }
20981 case 2:
20982 {
20983 (ri->d[rINDEX2])? (guysbuf[ri->npcdataref].flags |= guy_shield_right) : (guysbuf[ri->npcdataref].flags &= ~guy_shield_right);
20984 break;
20985 }
20986 case 3:
20987 {
20988 (ri->d[rINDEX2])? (guysbuf[ri->npcdataref].flags |= guy_shield_back) : (guysbuf[ri->npcdataref].flags &= ~guy_shield_back);
20989 break;
20990 }
20991 case 4:
20992 {
20993 (ri->d[rINDEX2])? (guysbuf[ri->npcdataref].flags |= guy_bkshield) : (guysbuf[ri->npcdataref].flags &= ~guy_bkshield);
20994 break;
20995 }
20996 default:
20997 {
20998 Z_scripterrlog("Invalid Array Index passed to npcdata->Shield[]: %d\n", indx);
20999 break;
21000 }
21001 }
21002 break;
21003 }
21004 }
21005
21006 case NPCDSHADOWSPR:
21007 {
21008 if(ri->npcdataref > (MAXNPCS-1) )
21009 {
21010 Z_scripterrlog("Invalid NPC ID passed to npcdata->ShadowSprite: %d\n", (ri->npcdataref*10000));
21011 }
21012 else
21013 {
21014 guysbuf[ri->npcdataref].spr_shadow = vbound(value/10000, 0, 255);
21015 }
21016 break;
21017 }
21018 case NPCDSPAWNSPR:
21019 {
21020 if(ri->npcdataref > (MAXNPCS-1) )
21021 {
21022 Z_scripterrlog("Invalid NPC ID passed to npcdata->SpawnSprite: %d\n", (ri->npcdataref*10000));
21023 }
21024 else
21025 {
21026 guysbuf[ri->npcdataref].spr_spawn = vbound(value/10000, 0, 255);
21027 }
21028 break;
21029 }
21030 case NPCDDEATHSPR:
21031 {
21032 if(ri->npcdataref > (MAXNPCS-1) )
21033 {
21034 Z_scripterrlog("Invalid NPC ID passed to npcdata->DeathSprite: %d\n", (ri->npcdataref*10000));
21035 }
21036 else
21037 {
21038 guysbuf[ri->npcdataref].spr_death = vbound(value/10000, 0, 255);
21039 }
21040 break;
21041 }
21042
21043
21044 ///----------------------------------------------------------------------------------------------------//
21045 //Dropset Variables
21046
21047 case DROPSETITEMS:
21048 {
21049 if(ri->dropsetref > MAXITEMDROPSETS)
21050 {
21051 Z_scripterrlog("Invalid dropset pointer %d\n", ri->dropsetref);
21052 break;
21053 }
21054 int32_t indx = ri->d[rINDEX]/10000;
21055 if(indx < 0 || indx > 9)
21056 {
21057 Z_scripterrlog("Invalid index passed to dropdata->Items[]: %d\n", indx);
21058 }
21059 else
21060 {
21061 item_drop_sets[ri->dropsetref].item[indx] = vbound(value / 10000, 0, MAXITEMS-1);
21062 }
21063 break;
21064 }
21065 case DROPSETCHANCES:
21066 {
21067 if(ri->dropsetref > MAXITEMDROPSETS)
21068 {
21069 Z_scripterrlog("Invalid dropset pointer %d\n", ri->dropsetref);
21070 break;
21071 }
21072 int32_t indx = ri->d[rINDEX]/10000;
21073 if(indx < 0 || indx > 9)
21074 {
21075 Z_scripterrlog("Invalid index passed to dropdata->Chances[]: %d\n", indx);
21076 }
21077 else
21078 {
21079 item_drop_sets[ri->dropsetref].chance[indx+1] = vbound((value / 10000),0,32767); //+1 is because '0' is 'nothing''s chance
21080 }
21081 break;
21082 }
21083 case DROPSETNULLCHANCE:
21084 {
21085 if(ri->dropsetref > MAXITEMDROPSETS)
21086 {
21087 Z_scripterrlog("Invalid dropset pointer %d\n", ri->dropsetref);
21088 break;
21089 }
21090 item_drop_sets[ri->dropsetref].chance[0] = vbound((value / 10000),0,32767);
21091 break;
21092 }
21093
21094 ///----------------------------------------------------------------------------------------------------//
21095 //Audio Variables
21096
21097 case AUDIOVOLUME:
21098 {
21099 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
21100 break;
21101
21102 int32_t indx = ri->d[rINDEX] / 10000;
21103 //int32_t vol = value / 10000;
21104 switch(indx)
21105 {
21106
21107 case 0: //midi volume
21108 {
21109 if ( !(FFCore.coreflags&FFCORE_SCRIPTED_MIDI_VOLUME) )
21110 {
21111 FFCore.usr_midi_volume = FFScript::do_getMIDI_volume();
21112 FFCore.SetFFEngineFlag(FFCORE_SCRIPTED_MIDI_VOLUME,true);
21113 }
21114 FFScript::do_setMIDI_volume(value / 10000);
21115 break;
21116 }
21117 case 1: //digi volume
21118 {
21119 if ( !(FFCore.coreflags&FFCORE_SCRIPTED_DIGI_VOLUME) )
21120 {
21121 FFCore.usr_digi_volume = FFScript::do_getDIGI_volume();
21122 FFCore.SetFFEngineFlag(FFCORE_SCRIPTED_DIGI_VOLUME,true);
21123 }
21124 FFScript::do_setDIGI_volume(value / 10000);
21125 break;
21126 }
21127 case 2: //emh music volume
21128 {
21129 if ( !(FFCore.coreflags&FFCORE_SCRIPTED_MUSIC_VOLUME) )
21130 {
21131 FFCore.usr_music_volume = FFScript::do_getMusic_volume();
21132 FFCore.SetFFEngineFlag(FFCORE_SCRIPTED_MUSIC_VOLUME,true);
21133 }
21134 FFScript::do_setMusic_volume(value / 10000);
21135 break;
21136 }
21137 case 3: //sfx volume
21138 {
21139 if ( !(FFCore.coreflags&FFCORE_SCRIPTED_SFX_VOLUME) )
21140 {
21141 FFCore.usr_sfx_volume = FFScript::do_getSFX_volume();
21142 FFCore.SetFFEngineFlag(FFCORE_SCRIPTED_SFX_VOLUME,true);
21143 }
21144 FFScript::do_setSFX_volume(value / 10000);
21145 break;
21146 }
21147 default:
21148 {
21149 Z_scripterrlog("Attempted to access an invalid index of Audio->Volume[]", indx);
21150 break;
21151 }
21152 }
21153 break;
21154 }
21155
21156 case AUDIOPAN:
21157 {
21158 if ( !(FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE) )
21159 {
21160 FFCore.usr_panstyle = FFScript::do_getSFX_pan();
21161 FFCore.SetFFEngineFlag(FFCORE_SCRIPTED_PANSTYLE,true);
21162 }
21163 FFScript::do_setSFX_pan(value/10000);
21164 break;
21165 }
21166
21167 ///----------------------------------------------------------------------------------------------------//
21168 //Graphics->
21169
21170 case NUMDRAWS:
21171 break;
21172
21173 case MAXDRAWS: break;
21174
21175 ///----------------------------------------------------------------------------------------------------//
21176 //Misc./Internal
21177 case SP:
21178 ri->sp = value / 10000;
21179 ri->sp &= MASK_SP;
21180 break;
21181
21182 case SP2:
21183 ri->sp = value;
21184 ri->sp &= MASK_SP;
21185 break;
21186
21187 case PC:
21188 ri->pc = value;
21189 break;
21190
21191 case SWITCHKEY:
21192 4 ri->switchkey = value;
21193 4 break;
21194
21195 case SCRIPTRAM:
21196 case GLOBALRAM:
21197 531793827 ArrayH::setElement(ri->d[rINDEX] / 10000, ri->d[rINDEX2] / 10000, value);
21198 531793827 break;
21199
21200 case SCRIPTRAMD:
21201 case GLOBALRAMD:
21202 ArrayH::setElement(ri->d[rINDEX] / 10000, 0, value);
21203 break;
21204
21205 case REFFFC:
21206
2/2
✓ Branch 0 taken 6374648 times.
✓ Branch 1 taken 639949442 times.
646324090 ri->ffcref = ZScriptVersion::ffcRefIsSpriteId() ? value : value / 10000;
21207 646324090 break;
21208
21209 case REFITEM:
21210 2239361 ri->itemref = value;
21211 2239361 break;
21212
21213 case REFITEMCLASS:
21214 6367264 ri->idata = value;
21215 6367264 break;
21216
21217 case REFLWPN:
21218 12117377 ri->lwpn = value;
21219 12117377 break;
21220
21221 case REFEWPN:
21222 46788128 ri->ewpn = value;
21223 46788128 break;
21224
21225 case REFNPC:
21226 162664378 ri->guyref = value;
21227 162664378 break;
21228
21229 case REFSPRITE:
21230 43204560 ri->spriteref = value;
21231 43204560 break;
21232
21233 88306945 case REFMAPDATA: ri->mapsref = value; break;
21234 case REFSCREENDATA: ri->screenref = value; break;
21235 838813 case REFCOMBODATA: ri->combosref = value; break;
21236 64 case REFSPRITEDATA: ri->spritedataref = value; break;
21237 410111 case REFBITMAP: ri->bitmapref = value; break;
21238 1 case REFNPCCLASS: ri->npcdataref = value; break;
21239
21240 77218 case REFDMAPDATA: ri->dmapsref = value; break;
21241 case REFSHOPDATA: ri->shopsref = value; break;
21242 124 case REFMSGDATA: ri->zmsgref = value; break;
21243 case REFUNTYPED: ri->untypedref = value; break;
21244
21245
21246 10 case REFDROPS: ri->dropsetref = value; break;
21247 case REFBOTTLETYPE: ri->bottletyperef = value; break;
21248 case REFBOTTLESHOP: ri->bottleshopref = value; break;
21249 8474345 case REFGENERICDATA: ri->genericdataref = value; break;
21250 case REFPONDS: ri->pondref = value; break;
21251 case REFWARPRINGS: ri->warpringref = value; break;
21252 case REFDOORS: ri->doorsref = value; break;
21253 case REFUICOLOURS: ri->zcoloursref = value; break;
21254 case REFRGB: ri->rgbref = value; break;
21255 case REFPALETTE: ri->paletteref = value; break;
21256 case REFTUNES: ri->tunesref = value; break;
21257 case REFPALCYCLE: ri->palcycleref = value; break;
21258 case REFGAMEDATA: ri->gamedataref = value; break;
21259 case REFCHEATS: ri->cheatsref = value; break;
21260 284 case REFFILE: ri->fileref = value; break;
21261 case REFDIRECTORY: ri->directoryref = value; break;
21262 case REFSTACK: ri->stackref = value; break;
21263 109743 case REFSUBSCREEN: ri->subdataref = value; break;
21264 20806 case REFSUBSCREENPAGE: ri->subpageref = value; break;
21265 103742 case REFSUBSCREENWIDG: ri->subwidgref = value; break;
21266 449481 case REFRNG: ri->rngref = value; break;
21267 case REFWEBSOCKET: ri->websocketref = value; break;
21268 388 case CLASS_THISKEY: ri->thiskey = value; break;
21269 120 case CLASS_THISKEY2: ri->thiskey2 = value; break;
21270 7263 case REFPALDATA: ri->paldataref = value; break;
21271
21272 //-------------------------------------------------------------------------------------------------
21273
21274 case PALDATACOLOR:
21275 {
21276 if (user_paldata* pd = checkPalData(ri->paldataref))
21277 {
21278 int32_t ind = ri->d[rINDEX] / 10000;
21279 if (unsigned(ind) >= PALDATA_NUM_COLORS)
21280 {
21281 Z_scripterrlog("Invalid color index (%d) passed to paldata->SetColor(). Valid indices are 0-255. Aborting.\n", ind);
21282 break;
21283 }
21284 int32_t clri = value;
21285
21286 RGB c = _RGB((clri >> 16) & 0xFF, (clri >> 8) & 0xFF, clri & 0xFF);
21287
21288 c.r = vbound(c.r, 0, scripting_max_color_val);
21289 c.g = vbound(c.g, 0, scripting_max_color_val);
21290 c.b = vbound(c.b, 0, scripting_max_color_val);
21291
21292 pd->set_color(ind, c);
21293 }
21294 break;
21295 }
21296 case PALDATAR:
21297 FFCore.do_paldata_setrgb(0, value / 10000);
21298 break;
21299 case PALDATAG:
21300 FFCore.do_paldata_setrgb(1, value / 10000);
21301 break;
21302 case PALDATAB:
21303 FFCore.do_paldata_setrgb(2, value / 10000);
21304 break;
21305
21306 //-------------------------------------------------------------------------------------------------
21307
21308 case GENDATARUNNING:
21309 {
21310
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 110 times.
110 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
21311 {
21312
1/2
✓ Branch 0 taken 110 times.
✗ Branch 1 not taken.
110 if(value)
21313 110 scr->launch();
21314 else scr->quit();
21315 110 }
21316 110 break;
21317 }
21318 case GENDATASIZE:
21319 {
21320
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
38 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
21321 {
21322 38 scr->dataResize(value/10000);
21323 38 }
21324 38 break;
21325 }
21326 case GENDATAEXITSTATE:
21327 {
21328 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
21329 {
21330 size_t indx = ri->d[rINDEX]/10000;
21331 if(indx >= GENSCR_NUMST)
21332 {
21333 scripting_log_error_with_context("Invalid index: {}", indx);
21334 break;
21335 }
21336 SETFLAG(scr->exitState, (1<<indx), value);
21337 }
21338 break;
21339 }
21340 case GENDATARELOADSTATE:
21341 {
21342
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 78 times.
78 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
21343 {
21344 78 size_t indx = ri->d[rINDEX]/10000;
21345
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 78 times.
78 if(indx >= GENSCR_NUMST)
21346 {
21347 scripting_log_error_with_context("Invalid index: {}", indx);
21348 break;
21349 }
21350
1/2
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
78 SETFLAG(scr->reloadState, (1<<indx), value);
21351 78 }
21352 78 break;
21353 }
21354 case GENDATAEVENTSTATE:
21355 {
21356
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 95 times.
95 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
21357 {
21358 95 size_t indx = ri->d[rINDEX]/10000;
21359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 95 times.
95 if(indx >= GENSCR_NUMEVENT)
21360 {
21361 scripting_log_error_with_context("Invalid index: {}", indx);
21362 break;
21363 }
21364
1/2
✓ Branch 0 taken 95 times.
✗ Branch 1 not taken.
95 SETFLAG(scr->eventstate, (1<<indx), value);
21365 95 }
21366 95 break;
21367 }
21368 case GENDATADATA:
21369 {
21370
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 214459 times.
214459 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
21371 {
21372 214459 size_t indx = ri->d[rINDEX]/10000;
21373
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 214459 times.
214459 if(indx >= scr->dataSize())
21374 {
21375 scripting_log_error_with_context("Invalid index: {}", indx);
21376 break;
21377 }
21378 214459 scr->data[indx] = value;
21379 214459 }
21380 214459 break;
21381 }
21382 case GENDATAINITD:
21383 {
21384 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
21385 {
21386 size_t indx = ri->d[rINDEX]/10000;
21387 if(indx >= 8)
21388 {
21389 scripting_log_error_with_context("Invalid index: {}", indx);
21390 break;
21391 }
21392 scr->initd[indx] = value;
21393 }
21394 break;
21395 }
21396
21397 //----------------------------------------------------------------------------------------------------//
21398
21399 case PORTALX:
21400 {
21401 if(portal* p = checkPortal(ri->portalref))
21402 p->x = zslongToFix(value);
21403 break;
21404 }
21405 case PORTALY:
21406 {
21407 if(portal* p = checkPortal(ri->portalref))
21408 p->y = zslongToFix(value);
21409 break;
21410 }
21411 case PORTALDMAP:
21412 {
21413 if(portal* p = checkPortal(ri->portalref))
21414 p->destdmap = vbound(value/10000,-1,MAXDMAPS-1);
21415 break;
21416 }
21417 case PORTALSCREEN:
21418 {
21419 if(portal* p = checkPortal(ri->portalref))
21420 p->destscr = vbound(value/10000,0,255);
21421 break;
21422 }
21423 case PORTALACLK:
21424 {
21425 if(portal* p = checkPortal(ri->portalref))
21426 p->aclk = vbound(value/10000, 0, 9999);
21427 break;
21428 }
21429 case PORTALAFRM:
21430 {
21431 if(portal* p = checkPortal(ri->portalref))
21432 p->aframe = vbound(value/10000, 0, 9999);
21433 break;
21434 }
21435 case PORTALOTILE:
21436 {
21437 if(portal* p = checkPortal(ri->portalref))
21438 p->o_tile = vbound(value/10000, 0, NEWMAXTILES-1);
21439 break;
21440 }
21441 case PORTALASPD:
21442 {
21443 if(portal* p = checkPortal(ri->portalref))
21444 p->aspd = vbound(value/10000, 0, 9999);
21445 break;
21446 }
21447 case PORTALFRAMES:
21448 {
21449 if(portal* p = checkPortal(ri->portalref))
21450 p->frames = vbound(value/10000, 0, 9999);
21451 break;
21452 }
21453 case PORTALSAVED:
21454 {
21455 if(ri->portalref < 0 || value < 0) break;
21456 if(portal* p = checkPortal(ri->portalref))
21457 {
21458 if(!value)
21459 p->saved_data = 0;
21460 else if(savedportal* sp = checkSavedPortal(value))
21461 p->saved_data = sp->getUID();
21462 }
21463 break;
21464 }
21465 case PORTALCLOSEDIS:
21466 {
21467 if(portal* p = checkPortal(ri->portalref))
21468 p->prox_active = value==0; //Inverted
21469 break;
21470 }
21471 case REFPORTAL:
21472 {
21473 ri->portalref = value;
21474 break;
21475 }
21476 case REFSAVPORTAL:
21477 {
21478 ri->saveportalref = value;
21479 break;
21480 }
21481 case PORTALWARPSFX:
21482 {
21483 if(portal* p = checkPortal(ri->portalref))
21484 p->wsfx = vbound(value/10000,0,255);
21485 break;
21486 }
21487 case PORTALWARPVFX:
21488 {
21489 if(portal* p = checkPortal(ri->portalref))
21490 p->weffect = vbound(value/10000,0,255);
21491 break;
21492 }
21493 case SAVEDPORTALX:
21494 {
21495 if(savedportal* p = checkSavedPortal(ri->saveportalref))
21496 p->x = value;
21497 break;
21498 }
21499 case SAVEDPORTALY:
21500 {
21501 if(savedportal* p = checkSavedPortal(ri->saveportalref))
21502 p->y = value;
21503 break;
21504 }
21505 case SAVEDPORTALSRCDMAP:
21506 {
21507 if(savedportal* p = checkSavedPortal(ri->saveportalref))
21508 p->srcdmap = vbound(value/10000, -1, MAXDMAPS-1);
21509 break;
21510 }
21511 case SAVEDPORTALDESTDMAP:
21512 {
21513 if(savedportal* p = checkSavedPortal(ri->saveportalref))
21514 p->destdmap = vbound(value/10000, -1, MAXDMAPS-1);
21515 break;
21516 }
21517 case SAVEDPORTALSRCSCREEN:
21518 {
21519 if(savedportal* p = checkSavedPortal(ri->saveportalref))
21520 p->srcscr = vbound(value/10000,0,255);
21521 break;
21522 }
21523 case SAVEDPORTALDSTSCREEN:
21524 {
21525 if(savedportal* p = checkSavedPortal(ri->saveportalref))
21526 p->destscr = vbound(value/10000,0,255);
21527 break;
21528 }
21529 case SAVEDPORTALWARPSFX:
21530 {
21531 if(savedportal* p = checkSavedPortal(ri->saveportalref))
21532 p->sfx = vbound(value/10000,0,255);
21533 break;
21534 }
21535 case SAVEDPORTALWARPVFX:
21536 {
21537 if(savedportal* p = checkSavedPortal(ri->saveportalref))
21538 p->warpfx = vbound(value/10000,0,255);
21539 break;
21540 }
21541 case SAVEDPORTALSPRITE:
21542 {
21543 if(savedportal* p = checkSavedPortal(ri->saveportalref))
21544 p->spr = vbound(value/10000,0,255);
21545 break;
21546 }
21547 case SAVEDPORTALPORTAL:
21548 {
21549 if(ri->saveportalref < 0 || value < 0) break;
21550 if(savedportal* sp = checkSavedPortal(ri->saveportalref))
21551 {
21552 int32_t id = getPortalFromSaved(sp);
21553 if(id == value) break; //no change
21554 portal* p = checkPortal(value);
21555 if(p)
21556 {
21557 p->saved_data = sp->getUID();
21558 if(id > 0)
21559 {
21560 portal* p = checkPortal(id);
21561 p->saved_data = 0;
21562 }
21563 }
21564 }
21565 break;
21566 }
21567
21568 case GAMENUMASUB:
21569 {
21570 if(value >= 0)
21571 {
21572 size_t sz = vbound(value/10000, 0, 256);
21573 while(subscreens_active.size() < sz)
21574 {
21575 auto& sub = subscreens_active.emplace_back();
21576 sub.sub_type = sstACTIVE;
21577 }
21578 while(subscreens_active.size() > sz)
21579 subscreens_active.pop_back();
21580 }
21581 break;
21582 }
21583 case GAMENUMPSUB:
21584 {
21585 if(value >= 0)
21586 {
21587 size_t sz = vbound(value/10000, 0, 256);
21588 while(subscreens_passive.size() < sz)
21589 {
21590 auto& sub = subscreens_passive.emplace_back();
21591 sub.sub_type = sstPASSIVE;
21592 }
21593 while(subscreens_passive.size() > sz)
21594 subscreens_passive.pop_back();
21595 }
21596 break;
21597 }
21598 case GAMENUMOSUB:
21599 {
21600 if(value >= 0)
21601 {
21602 size_t sz = vbound(value/10000, 0, 256);
21603 while(subscreens_overlay.size() < sz)
21604 {
21605 auto& sub = subscreens_overlay.emplace_back();
21606 sub.sub_type = sstOVERLAY;
21607 }
21608 while(subscreens_overlay.size() > sz)
21609 subscreens_overlay.pop_back();
21610 }
21611 break;
21612 }
21613 ///----------------------------------------------------------------------------------------------------//
21614
21615 case SUBDATACURPG:
21616 {
21617
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
21618
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
6 if(sub->sub_type == sstACTIVE)
21619 3 sub->curpage = vbound(value/10000,0,sub->pages.size()-1);
21620 3 break;
21621 }
21622 case SUBDATANUMPG:
21623 {
21624 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
21625 if(sub->sub_type == sstACTIVE && value >= 10000)
21626 {
21627 size_t sz = value/10000;
21628 while(sub->pages.size() < sz)
21629 if(!sub->add_page(MAX_SUBSCR_PAGES))
21630 break;
21631 while(sub->pages.size() > sz)
21632 sub->delete_page(sub->pages.size()-1);
21633 }
21634 break;
21635 }
21636 case SUBDATAPAGES: break; //READONLY
21637 case SUBDATATYPE: break; //READONLY
21638 case SUBDATAFLAGS:
21639 {
21640 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
21641 {
21642 size_t indx = ri->d[rINDEX]/10000;
21643 size_t sz = 0;
21644 switch(sub->sub_type)
21645 {
21646 case sstACTIVE:
21647 sz = 2;
21648 break;
21649 case sstPASSIVE:
21650 sz = 0;
21651 break;
21652 case sstOVERLAY:
21653 sz = 0;
21654 break;
21655 }
21656 if(indx >= sz)
21657 {
21658 Z_scripterrlog("Bad index '%d' to array "
21659 "'subscreendata->Flags[]' of size '%d'\n", indx, sz);
21660 }
21661 else
21662 SETFLAG(sub->flags,(1<<indx),value);
21663 }
21664 break;
21665 }
21666 ///---- ACTIVE SUBSCREENS ONLY
21667 case SUBDATACURSORPOS:
21668 {
21669 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21670 {
21671 SubscrPage& pg = sub->cur_page();
21672 //Should this be sanity checked? Or should nulling out
21673 // the cursor by setting it invalid be allowed? -Em
21674 pg.cursor_pos = vbound(value/10000,0,255);
21675 }
21676 break;
21677 }
21678 case SUBDATASCRIPT:
21679 {
21680 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21681 sub->script = vbound(value/10000,0,NUMSCRIPTSSUBSCREEN-1);
21682 break;
21683 }
21684 case SUBDATAINITD:
21685 {
21686 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21687 {
21688 size_t indx = ri->d[rINDEX]/10000;
21689 if(indx >= 8)
21690 {
21691 Z_scripterrlog("Bad index '%d' to array "
21692 "'subscreendata->InitD[8]'\n", indx);
21693 }
21694 else
21695 sub->initd[indx] = value;
21696 }
21697 break;
21698 }
21699 case SUBDATABTNLEFT:
21700 {
21701 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21702 {
21703 size_t indx = ri->d[rINDEX]/10000;
21704 if(indx >= 8)
21705 {
21706 Z_scripterrlog("Bad index '%d' to array "
21707 "'subscreendata->BtnPageLeft[8]'\n", indx);
21708 }
21709 else
21710 SETFLAG(sub->btn_left,(1<<indx),value);
21711 }
21712 break;
21713 }
21714 case SUBDATABTNRIGHT:
21715 {
21716 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21717 {
21718 size_t indx = ri->d[rINDEX]/10000;
21719 if(indx >= 8)
21720 {
21721 Z_scripterrlog("Bad index '%d' to array "
21722 "'subscreendata->BtnPageRight[8]'\n", indx);
21723 }
21724 else
21725 SETFLAG(sub->btn_right,(1<<indx),value);
21726 }
21727 break;
21728 }
21729 case SUBDATATRANSLEFTTY:
21730 {
21731 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21732 {
21733 auto& trans = sub->trans_left;
21734 trans.type = vbound(value/10000,0,sstrMAX-1);
21735 }
21736 break;
21737 }
21738 case SUBDATATRANSLEFTSFX:
21739 {
21740 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21741 {
21742 auto& trans = sub->trans_left;
21743 trans.tr_sfx = vbound(value/10000,0,255);
21744 }
21745 break;
21746 }
21747 case SUBDATATRANSLEFTFLAGS:
21748 {
21749 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21750 {
21751 auto& trans = sub->trans_left;
21752 size_t indx = ri->d[rINDEX]/10000;
21753 if(indx >= SUBSCR_TRANS_NUMFLAGS)
21754 {
21755 Z_scripterrlog("Bad index '%d' to array "
21756 "'subscreendata->TransLeftFlags[%d]'\n", indx, SUBSCR_TRANS_NUMFLAGS);
21757 }
21758 else
21759 SETFLAG(trans.flags,(1<<indx),value);
21760 }
21761 break;
21762 }
21763 case SUBDATATRANSLEFTARGS:
21764 {
21765 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21766 {
21767 auto& trans = sub->trans_left;
21768 size_t indx = ri->d[rINDEX]/10000;
21769 if(indx >= SUBSCR_TRANSITION_MAXARG)
21770 {
21771 Z_scripterrlog("Bad index '%d' to array "
21772 "'subscreendata->TransLeftArgs[%d]'\n", indx, SUBSCR_TRANSITION_MAXARG);
21773 }
21774 else
21775 trans.arg[indx] = value/SubscrTransition::argScale(trans.type,indx);
21776 }
21777 break;
21778 }
21779 case SUBDATATRANSRIGHTTY:
21780 {
21781 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21782 {
21783 auto& trans = sub->trans_right;
21784 trans.type = vbound(value/10000,0,sstrMAX-1);
21785 }
21786 break;
21787 }
21788 case SUBDATATRANSRIGHTSFX:
21789 {
21790 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21791 {
21792 auto& trans = sub->trans_right;
21793 trans.tr_sfx = vbound(value/10000,0,255);
21794 }
21795 break;
21796 }
21797 case SUBDATATRANSRIGHTFLAGS:
21798 {
21799 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21800 {
21801 auto& trans = sub->trans_right;
21802 size_t indx = ri->d[rINDEX]/10000;
21803 if(indx >= SUBSCR_TRANS_NUMFLAGS)
21804 {
21805 Z_scripterrlog("Bad index '%d' to array "
21806 "'subscreendata->TransRightFlags[%d]'\n", indx, SUBSCR_TRANS_NUMFLAGS);
21807 }
21808 else
21809 SETFLAG(trans.flags,(1<<indx),value);
21810 }
21811 break;
21812 }
21813 case SUBDATATRANSRIGHTARGS:
21814 {
21815 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21816 {
21817 auto& trans = sub->trans_right;
21818 size_t indx = ri->d[rINDEX]/10000;
21819 if(indx >= SUBSCR_TRANSITION_MAXARG)
21820 {
21821 Z_scripterrlog("Bad index '%d' to array "
21822 "'subscreendata->TransRightArgs[%d]'\n", indx, SUBSCR_TRANSITION_MAXARG);
21823 }
21824 else
21825 trans.arg[indx] = value/SubscrTransition::argScale(trans.type,indx);
21826 }
21827 break;
21828 }
21829 case SUBDATASELECTORDSTX:
21830 {
21831 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21832 sub->selector_setting.x = vbound(value/10000,-32768,32767);
21833 break;
21834 }
21835 case SUBDATASELECTORDSTY:
21836 {
21837 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21838 sub->selector_setting.y = vbound(value/10000,-32768,32767);
21839 break;
21840 }
21841 case SUBDATASELECTORDSTW:
21842 {
21843 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21844 sub->selector_setting.w = vbound(value/10000,-32768,32767);
21845 break;
21846 }
21847 case SUBDATASELECTORDSTH:
21848 {
21849 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21850 sub->selector_setting.h = vbound(value/10000,-32768,32767);
21851 break;
21852 }
21853 case SUBDATASELECTORWID:
21854 {
21855 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21856 {
21857 size_t indx = ri->d[rINDEX]/10000;
21858 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
21859 {
21860 Z_scripterrlog("Bad index '%d' to array 'subscreendata->"
21861 "SelectorDestWid[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
21862 }
21863 else
21864 sub->selector_setting.tileinfo[indx].sw = vbound(value/10000,0,65535);
21865 }
21866 break;
21867 }
21868 case SUBDATASELECTORHEI:
21869 {
21870 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21871 {
21872 size_t indx = ri->d[rINDEX]/10000;
21873 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
21874 {
21875 Z_scripterrlog("Bad index '%d' to array 'subscreendata->"
21876 "SelectorDestHei[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
21877 }
21878 else
21879 sub->selector_setting.tileinfo[indx].sh = vbound(value/10000,0,65535);
21880 }
21881 break;
21882 }
21883 case SUBDATASELECTORTILE:
21884 {
21885 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21886 {
21887 size_t indx = ri->d[rINDEX]/10000;
21888 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
21889 {
21890 Z_scripterrlog("Bad index '%d' to array 'subscreendata->"
21891 "SelectorTile[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
21892 }
21893 else
21894 sub->selector_setting.tileinfo[indx].tile = vbound(value/10000,0,NEWMAXTILES-1);
21895 }
21896 break;
21897 }
21898 case SUBDATASELECTORCSET:
21899 {
21900 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21901 {
21902 size_t indx = ri->d[rINDEX]/10000;
21903 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
21904 {
21905 Z_scripterrlog("Bad index '%d' to array 'subscreendata->"
21906 "SelectorCSet[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
21907 }
21908 else
21909 {
21910 byte& cs = sub->selector_setting.tileinfo[indx].cset;
21911 cs = (cs&0xF0)|vbound(value/10000,0,0x0F);
21912 }
21913 }
21914 break;
21915 }
21916 case SUBDATASELECTORFLASHCSET:
21917 {
21918 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21919 {
21920 size_t indx = ri->d[rINDEX]/10000;
21921 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
21922 {
21923 Z_scripterrlog("Bad index '%d' to array 'subscreendata->"
21924 "SelectorFlashCSet[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
21925 }
21926 else
21927 {
21928 byte& cs = sub->selector_setting.tileinfo[indx].cset;
21929 cs = (cs&0x0F)|(vbound(value/10000,0,0x0F)<<4);
21930 }
21931 }
21932 break;
21933 }
21934 case SUBDATASELECTORFRM:
21935 {
21936 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21937 {
21938 size_t indx = ri->d[rINDEX]/10000;
21939 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
21940 {
21941 Z_scripterrlog("Bad index '%d' to array 'subscreendata->"
21942 "SelectorFrames[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
21943 }
21944 else
21945 sub->selector_setting.tileinfo[indx].frames = vbound(value/10000,1,255);
21946 }
21947 break;
21948 }
21949 case SUBDATASELECTORASPD:
21950 {
21951 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21952 {
21953 size_t indx = ri->d[rINDEX]/10000;
21954 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
21955 {
21956 Z_scripterrlog("Bad index '%d' to array 'subscreendata->"
21957 "SelectorASpeed[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
21958 }
21959 else
21960 sub->selector_setting.tileinfo[indx].speed = vbound(value/10000,1,255);
21961 }
21962 break;
21963 }
21964 case SUBDATASELECTORDELAY:
21965 {
21966 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21967 {
21968 size_t indx = ri->d[rINDEX]/10000;
21969 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
21970 {
21971 Z_scripterrlog("Bad index '%d' to array 'subscreendata->"
21972 "SelectorDelay[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
21973 }
21974 else
21975 sub->selector_setting.tileinfo[indx].delay = vbound(value/10000,0,255);
21976 }
21977 break;
21978 }
21979 ///---- CURRENTLY OPEN ACTIVE SUBSCREEN ONLY
21980 case SUBDATATRANSCLK:
21981 {
21982
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
21983 {
21984
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(sub != new_subscreen_active)
21985 Z_scripterrlog("'subscreendata->TransClock' is only"
21986 " valid for the current active subscreen!\n");
21987
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 else if(subscreen_open)
21988 {
21989 11 int val = value/10000;
21990
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(val < 0)
21991 subscrpg_clear_animation();
21992
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 else if(!subscr_pg_animating)
21993 {
21994 11 SubscrTransition tr = subscr_pg_transition;
21995 11 tr.tr_sfx = 0;
21996 11 subscrpg_animate(subscr_pg_from,subscr_pg_to,tr,*new_subscreen_active);
21997 11 subscr_pg_clk = val;
21998 11 }
21999 else subscr_pg_clk = val;
22000 11 }
22001 11 }
22002 11 break;
22003 }
22004 case SUBDATATRANSTY:
22005 {
22006
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
22007 {
22008 11 auto& trans = subscr_pg_transition;
22009
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(sub != new_subscreen_active)
22010 Z_scripterrlog("'subscreendata->TransType' is only"
22011 " valid for the current active subscreen!\n");
22012
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 else if(subscreen_open)
22013 11 trans.type = vbound(value/10000,0,sstrMAX-1);
22014 11 }
22015 11 break;
22016 }
22017 case SUBDATATRANSFLAGS:
22018 {
22019 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
22020 {
22021 auto& trans = subscr_pg_transition;
22022 size_t indx = ri->d[rINDEX]/10000;
22023 if(indx >= SUBSCR_TRANS_NUMFLAGS)
22024 {
22025 Z_scripterrlog("Bad index '%d' to array "
22026 "'subscreendata->TransFlags[%d]'\n", indx, SUBSCR_TRANS_NUMFLAGS);
22027 }
22028 else if(sub != new_subscreen_active)
22029 Z_scripterrlog("'subscreendata->TransType' is only"
22030 " valid for the current active subscreen!\n");
22031 else if(subscreen_open)
22032 SETFLAG(trans.flags,(1<<indx),value);
22033 }
22034 break;
22035 }
22036 case SUBDATATRANSARGS:
22037 {
22038
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
22039 {
22040 22 auto& trans = subscr_pg_transition;
22041 22 size_t indx = ri->d[rINDEX]/10000;
22042
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if(indx >= SUBSCR_TRANSITION_MAXARG)
22043 {
22044 Z_scripterrlog("Bad index '%d' to array "
22045 "'subscreendata->TransArgs[%d]'\n", indx, SUBSCR_TRANSITION_MAXARG);
22046 }
22047
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 else if(sub != new_subscreen_active)
22048 Z_scripterrlog("'subscreendata->TransType' is only"
22049 " valid for the current active subscreen!\n");
22050
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 else if(subscreen_open)
22051 22 trans.arg[indx] = value/SubscrTransition::argScale(trans.type,indx);
22052 22 }
22053 22 break;
22054 }
22055 case SUBDATATRANSFROMPG:
22056 {
22057
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
22058 {
22059
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(sub != new_subscreen_active)
22060 Z_scripterrlog("'subscreendata->TransFromPage' is only"
22061 " valid for the current active subscreen!\n");
22062
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 else if(subscreen_open)
22063 11 subscr_pg_from = vbound(value/10000,0,sub->pages.size()-1);
22064 11 }
22065 11 break;
22066 }
22067 case SUBDATATRANSTOPG:
22068 {
22069
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
22070 {
22071
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(sub != new_subscreen_active)
22072 Z_scripterrlog("'subscreendata->TransToPage' is only"
22073 " valid for the current active subscreen!\n");
22074
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 else if(subscreen_open)
22075 11 subscr_pg_to = vbound(value/10000,0,sub->pages.size()-1);
22076 11 }
22077 11 break;
22078 }
22079
22080 ///----------------------------------------------------------------------------------------------------//
22081 case SUBPGINDEX: break; //READ-ONLY
22082 case SUBPGNUMWIDG: break; //READ-ONLY
22083 case SUBPGWIDGETS: break; //READ-ONLY
22084 case SUBPGSUBDATA: break; //READ-ONLY
22085 case SUBPGCURSORPOS:
22086 {
22087 if(SubscrPage* pg = checkSubPage(ri->subpageref))
22088 pg->cursor_pos = vbound(value/10000,0,255);
22089 break;
22090 }
22091 ///----------------------------------------------------------------------------------------------------//
22092 ///---- ANY WIDGET TYPE
22093 case SUBWIDGTYPE: break; //READ-ONLY
22094 case SUBWIDGINDEX: break; //READ-ONLY
22095 case SUBWIDGPAGE: break; //READ-ONLY
22096 case SUBWIDGDISPITM: break; //READ-ONLY
22097 case SUBWIDGEQPITM: break; //READ-ONLY
22098 case SUBWIDGPOS:
22099 {
22100 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22101 widg->pos = vbound(value/10000,0,255);
22102 break;
22103 }
22104 case SUBWIDGPOSES:
22105 {
22106 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22107 {
22108 size_t indx = ri->d[rINDEX]/10000;
22109 if(indx >= 4)
22110 {
22111 Z_scripterrlog("Bad index '%d' to array "
22112 "'subscreenwidget->PosDirs[%d]'\n", indx, 4);
22113 }
22114 else
22115 {
22116 byte val = vbound(value/10000,0,255);
22117 switch(indx)
22118 {
22119 case up:
22120 widg->pos_up = val;
22121 break;
22122 case down:
22123 widg->pos_down = val;
22124 break;
22125 case left:
22126 widg->pos_left = val;
22127 break;
22128 case right:
22129 widg->pos_right = val;
22130 break;
22131 }
22132 }
22133 }
22134 break;
22135 }
22136 case SUBWIDGPOSFLAG:
22137 {
22138 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22139 {
22140 size_t indx = ri->d[rINDEX]/10000;
22141 if(indx >= sspNUM)
22142 {
22143 Z_scripterrlog("Bad index '%d' to array "
22144 "'subscreenwidget->VisibleFlags[%d]'\n", indx, sspNUM);
22145 }
22146 else
22147 {
22148 SETFLAG(widg->posflags, 1<<indx, value);
22149 }
22150 }
22151 break;
22152 }
22153 case SUBWIDGX:
22154 {
22155
1/2
✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
132 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22156 132 widg->x = vbound(value/10000,-32768,32767);
22157 132 break;
22158 }
22159 case SUBWIDGY:
22160 {
22161
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4247 times.
4247 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22162 4247 widg->y = vbound(value/10000,-32768,32767);
22163 4247 break;
22164 }
22165 case SUBWIDGW:
22166 {
22167 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22168 widg->w = vbound(value/10000,0,65535);
22169 break;
22170 }
22171 case SUBWIDGH:
22172 {
22173 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22174 widg->h = vbound(value/10000,0,65535);
22175 break;
22176 }
22177 case SUBWIDGGENFLAG:
22178 {
22179 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22180 {
22181 size_t indx = ri->d[rINDEX]/10000;
22182 if(indx >= SUBSCRFLAG_GEN_COUNT)
22183 {
22184 Z_scripterrlog("Bad index '%d' to array "
22185 "'subscreenwidget->GenFlags[%d]'\n", indx, SUBSCRFLAG_GEN_COUNT);
22186 }
22187 else
22188 {
22189 SETFLAG(widg->genflags, 1<<indx, value);
22190 }
22191 }
22192 break;
22193 }
22194 case SUBWIDGFLAG:
22195 {
22196 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22197 {
22198 size_t indx = ri->d[rINDEX]/10000;
22199 byte sz = widg->numFlags();
22200 if (BC::checkIndex2(indx, sz) == SH::_NoError)
22201 {
22202 SETFLAG(widg->flags, 1<<indx, value);
22203 }
22204 }
22205 break;
22206 }
22207 case SUBWIDGREQOWNITEMS:
22208 {
22209 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22210 {
22211 size_t indx = ri->d[rINDEX]/10000;
22212 if (BC::checkIndex2(indx, MAXITEMS) == SH::_NoError)
22213 {
22214 if(value)
22215 widg->req_owned_items.insert(indx);
22216 else
22217 widg->req_owned_items.erase(indx);
22218 }
22219 }
22220 break;
22221 }
22222 case SUBWIDGREQUNOWNITEMS:
22223 {
22224 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22225 {
22226 size_t indx = ri->d[rINDEX]/10000;
22227 if (BC::checkIndex2(indx, MAXITEMS) == SH::_NoError)
22228 {
22229 if(value)
22230 widg->req_unowned_items.insert(indx);
22231 else
22232 widg->req_unowned_items.erase(indx);
22233 }
22234 }
22235 break;
22236 }
22237 case SUBWIDGREQCOUNTER:
22238 {
22239 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22240 widg->req_counter = vbound(value/10000,sscMIN,MAX_COUNTERS);
22241 break;
22242 }
22243 case SUBWIDGREQCOUNTERCOND:
22244 {
22245 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22246 widg->req_counter_cond_type = vbound(value/10000,CONDTY_NONE,CONDTY_MAX-1);
22247 break;
22248 }
22249 case SUBWIDGREQCOUNTERVAL:
22250 {
22251 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22252 widg->req_counter_val = vbound(value/10000,0,65535);
22253 break;
22254 }
22255 case SUBWIDGREQLITEMS:
22256 {
22257 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22258 widg->req_litems = vbound(value/10000,0,liALL);
22259 break;
22260 }
22261 case SUBWIDGREQLITEMLEVEL:
22262 {
22263 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22264 widg->req_litem_level = vbound(value/10000,-1,MAXLEVELS);
22265 break;
22266 }
22267 case SUBWIDGREQSCRIPTDISABLED:
22268 {
22269 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22270 widg->is_disabled = value != 0;
22271 break;
22272 }
22273 ///---- ACTIVE SUBSCREENS ONLY
22274 case SUBWIDGSELECTORDSTX:
22275 {
22276 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22277 widg->selector_override.x = vbound(value/10000,-32768,32767);
22278 break;
22279 }
22280 case SUBWIDGSELECTORDSTY:
22281 {
22282 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22283 widg->selector_override.y = vbound(value/10000,-32768,32767);
22284 break;
22285 }
22286 case SUBWIDGSELECTORDSTW:
22287 {
22288 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22289 widg->selector_override.w = vbound(value/10000,-32768,32767);
22290 break;
22291 }
22292 case SUBWIDGSELECTORDSTH:
22293 {
22294 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22295 widg->selector_override.h = vbound(value/10000,-32768,32767);
22296 break;
22297 }
22298 case SUBWIDGSELECTORWID:
22299 {
22300 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22301 {
22302 size_t indx = ri->d[rINDEX]/10000;
22303 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
22304 {
22305 Z_scripterrlog("Bad index '%d' to array 'subscreenwidget->"
22306 "SelectorDestWid[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
22307 }
22308 else
22309 widg->selector_override.tileinfo[indx].sw = vbound(value/10000,0,65535);
22310 }
22311 break;
22312 }
22313 case SUBWIDGSELECTORHEI:
22314 {
22315 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22316 {
22317 size_t indx = ri->d[rINDEX]/10000;
22318 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
22319 {
22320 Z_scripterrlog("Bad index '%d' to array 'subscreenwidget->"
22321 "SelectorDestHei[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
22322 }
22323 else
22324 widg->selector_override.tileinfo[indx].sh = vbound(value/10000,0,65535);
22325 }
22326 break;
22327 }
22328 case SUBWIDGSELECTORTILE:
22329 {
22330 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22331 {
22332 size_t indx = ri->d[rINDEX]/10000;
22333 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
22334 {
22335 Z_scripterrlog("Bad index '%d' to array 'subscreenwidget->"
22336 "SelectorTile[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
22337 }
22338 else
22339 widg->selector_override.tileinfo[indx].tile = vbound(value/10000,0,NEWMAXTILES-1);
22340 }
22341 break;
22342 }
22343 case SUBWIDGSELECTORCSET:
22344 {
22345 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22346 {
22347 size_t indx = ri->d[rINDEX]/10000;
22348 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
22349 {
22350 Z_scripterrlog("Bad index '%d' to array 'subscreenwidget->"
22351 "SelectorCSet[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
22352 }
22353 else
22354 {
22355 byte& cs = widg->selector_override.tileinfo[indx].cset;
22356 cs = (cs&0xF0)|vbound(value/10000,0,0x0F);
22357 }
22358 }
22359 break;
22360 }
22361 case SUBWIDGSELECTORFLASHCSET:
22362 {
22363 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22364 {
22365 size_t indx = ri->d[rINDEX]/10000;
22366 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
22367 {
22368 Z_scripterrlog("Bad index '%d' to array 'subscreenwidget->"
22369 "SelectorFlashCSet[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
22370 }
22371 else
22372 {
22373 byte& cs = widg->selector_override.tileinfo[indx].cset;
22374 cs = (cs&0x0F)|(vbound(value/10000,0,0x0F)<<4);
22375 }
22376 }
22377 break;
22378 }
22379 case SUBWIDGSELECTORFRM:
22380 {
22381 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22382 {
22383 size_t indx = ri->d[rINDEX]/10000;
22384 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
22385 {
22386 Z_scripterrlog("Bad index '%d' to array 'subscreenwidget->"
22387 "SelectorFrames[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
22388 }
22389 else
22390 widg->selector_override.tileinfo[indx].frames = vbound(value/10000,1,255);
22391 }
22392 break;
22393 }
22394 case SUBWIDGSELECTORASPD:
22395 {
22396 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22397 {
22398 size_t indx = ri->d[rINDEX]/10000;
22399 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
22400 {
22401 Z_scripterrlog("Bad index '%d' to array 'subscreenwidget->"
22402 "SelectorASpeed[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
22403 }
22404 else
22405 widg->selector_override.tileinfo[indx].speed = vbound(value/10000,1,255);
22406 }
22407 break;
22408 }
22409 case SUBWIDGSELECTORDELAY:
22410 {
22411 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22412 {
22413 size_t indx = ri->d[rINDEX]/10000;
22414 if(indx >= SUBSCR_SELECTOR_NUMTILEINFO)
22415 {
22416 Z_scripterrlog("Bad index '%d' to array 'subscreenwidget->"
22417 "SelectorDelay[%d]'\n", indx, SUBSCR_SELECTOR_NUMTILEINFO);
22418 }
22419 else
22420 widg->selector_override.tileinfo[indx].delay = vbound(value/10000,0,255);
22421 }
22422 break;
22423 }
22424
22425 case SUBWIDGPRESSSCRIPT:
22426 {
22427 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22428 widg->generic_script = vbound(value/10000,0,NUMSCRIPTSGENERIC-1);
22429 break;
22430 }
22431 case SUBWIDGPRESSINITD:
22432 {
22433 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22434 {
22435 size_t indx = ri->d[rINDEX]/10000;
22436 if(indx >= 8)
22437 {
22438 Z_scripterrlog("Bad index '%d' to array "
22439 "'subscreenwidget->PressInitD[8]'\n", indx);
22440 }
22441 else
22442 widg->generic_initd[indx] = value;
22443 }
22444 break;
22445 }
22446 case SUBWIDGBTNPRESS:
22447 {
22448 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22449 {
22450 size_t indx = ri->d[rINDEX]/10000;
22451 if(indx >= 8)
22452 {
22453 Z_scripterrlog("Bad index '%d' to array "
22454 "'subscreenwidget->BtnPressScript[8]'\n", indx);
22455 }
22456 else
22457 SETFLAG(widg->gen_script_btns,(1<<indx),value);
22458 }
22459 break;
22460 }
22461 case SUBWIDGBTNPG:
22462 {
22463 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22464 {
22465 size_t indx = ri->d[rINDEX]/10000;
22466 if(indx >= 8)
22467 {
22468 Z_scripterrlog("Bad index '%d' to array "
22469 "'subscreenwidget->BtnPageChange[8]'\n", indx);
22470 }
22471 else
22472 SETFLAG(widg->pg_btns,(1<<indx),value);
22473 }
22474 break;
22475 }
22476 case SUBWIDGPGMODE:
22477 {
22478 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22479 widg->pg_mode = vbound(value/10000,0,PGGOTO_MAX-1);
22480 break;
22481 }
22482 case SUBWIDGPGTARG:
22483 {
22484 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22485 widg->pg_targ = vbound(value/10000,0,MAX_SUBSCR_PAGES-1);
22486 break;
22487 }
22488
22489 case SUBWIDGTRANSPGTY:
22490 {
22491 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22492 {
22493 auto& trans = widg->pg_trans;
22494 trans.type = vbound(value/10000,0,sstrMAX-1);
22495 }
22496 break;
22497 }
22498 case SUBWIDGTRANSPGSFX:
22499 {
22500 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22501 {
22502 auto& trans = widg->pg_trans;
22503 trans.tr_sfx = vbound(value/10000,0,255);
22504 }
22505 break;
22506 }
22507 case SUBWIDGTRANSPGFLAGS:
22508 {
22509 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22510 {
22511 auto& trans = widg->pg_trans;
22512 size_t indx = ri->d[rINDEX]/10000;
22513 if(indx >= SUBSCR_TRANS_NUMFLAGS)
22514 {
22515 Z_scripterrlog("Bad index '%d' to array "
22516 "'subscreenwidget->PageTransFlags[%d]'\n", indx, SUBSCR_TRANS_NUMFLAGS);
22517 }
22518 else
22519 SETFLAG(trans.flags,(1<<indx),value);
22520 }
22521 break;
22522 }
22523 case SUBWIDGTRANSPGARGS:
22524 {
22525 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
22526 {
22527 auto& trans = widg->pg_trans;
22528 size_t indx = ri->d[rINDEX]/10000;
22529 if(indx >= SUBSCR_TRANSITION_MAXARG)
22530 {
22531 Z_scripterrlog("Bad index '%d' to array "
22532 "'subscreenwidget->PageTransArgs[%d]'\n", indx, SUBSCR_TRANSITION_MAXARG);
22533 }
22534 else
22535 trans.arg[indx] = value/SubscrTransition::argScale(trans.type,indx);
22536 }
22537 break;
22538 }
22539 ///---- VARYING WIDGET TYPES
22540 case SUBWIDGTY_CSET:
22541 {
22542 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22543 {
22544 auto val = vbound(value/10000,-sscsMAX,15);
22545 size_t indx = ri->d[rINDEX]/10000;
22546 size_t sz = 0;
22547 byte ty = widg->getType();
22548 switch(ty)
22549 {
22550 case widgFRAME:
22551 case widgMCGUFF:
22552 case widgTILEBLOCK:
22553 case widgMINITILE:
22554 sz = 1;
22555 break;
22556 case widgLGAUGE:
22557 case widgMGAUGE:
22558 case widgMISCGAUGE:
22559 sz = 4;
22560 break;
22561 default:
22562 sz = 0;
22563 bad_subwidg_type(false, ty);
22564 break;
22565 }
22566 if(!sz) break;
22567 if(indx >= sz)
22568 {
22569 Z_scripterrlog("Bad index '%d' to array "
22570 "'subscreenwidget->CSet[%d]'\n", indx, sz);
22571 break;
22572 }
22573 switch(ty)
22574 {
22575 case widgFRAME:
22576 ((SW_2x2Frame*)widg)->cs.set_int_cset(val);
22577 break;
22578 case widgMCGUFF:
22579 ((SW_McGuffin*)widg)->cs.set_int_cset(val);
22580 break;
22581 case widgTILEBLOCK:
22582 ((SW_TileBlock*)widg)->cs.set_int_cset(val);
22583 break;
22584 case widgMINITILE:
22585 ((SW_MiniTile*)widg)->cs.set_int_cset(val);
22586 break;
22587 case widgLGAUGE:
22588 case widgMGAUGE:
22589 case widgMISCGAUGE:
22590 val = vbound(value/10000,0,15);
22591 ((SW_GaugePiece*)widg)->mts[indx].cset = val;
22592 break;
22593 }
22594 }
22595 break;
22596 }
22597 case SUBWIDGTY_TILE:
22598 {
22599
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 102 times.
102 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22600 {
22601 102 auto val = vbound(value/10000,0,NEWMAXTILES-1);
22602 102 size_t indx = ri->d[rINDEX]/10000;
22603 102 size_t sz = 0;
22604 102 byte ty = widg->getType();
22605
1/3
✓ Branch 0 taken 102 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
102 switch(ty)
22606 {
22607 case widgFRAME:
22608 case widgMCGUFF:
22609 case widgTILEBLOCK:
22610 case widgMINITILE:
22611 102 sz = 1;
22612 102 break;
22613 case widgLGAUGE:
22614 case widgMGAUGE:
22615 case widgMISCGAUGE:
22616 sz = 4;
22617 break;
22618 default:
22619 sz = 0;
22620 bad_subwidg_type(false, ty);
22621 break;
22622 }
22623
1/2
✓ Branch 0 taken 102 times.
✗ Branch 1 not taken.
102 if(!sz) break;
22624
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 102 times.
102 if(indx >= sz)
22625 {
22626 Z_scripterrlog("Bad index '%d' to array "
22627 "'subscreenwidget->Tile[%d]'\n", indx, sz);
22628 break;
22629 }
22630
1/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 102 times.
✗ Branch 5 not taken.
102 switch(ty)
22631 {
22632 case widgFRAME:
22633 ((SW_2x2Frame*)widg)->tile = val;
22634 break;
22635 case widgMCGUFF:
22636 ((SW_McGuffin*)widg)->tile = val;
22637 break;
22638 case widgTILEBLOCK:
22639 102 ((SW_TileBlock*)widg)->tile = val;
22640 102 break;
22641 case widgMINITILE:
22642 val = vbound(value/10000,-ssmstMAX,NEWMAXTILES-1);
22643 ((SW_MiniTile*)widg)->set_int_tile(val);
22644 break;
22645 case widgLGAUGE:
22646 case widgMGAUGE:
22647 case widgMISCGAUGE:
22648 ((SW_GaugePiece*)widg)->mts[indx].setTile(val);
22649 break;
22650 }
22651 102 }
22652 102 break;
22653 }
22654 case SUBWIDGTY_FONT:
22655 {
22656 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22657 {
22658 auto val = vbound(value/10000,0,font_max-1);
22659 auto ty = widg->getType();
22660 switch(ty)
22661 {
22662 case widgTEXT:
22663 ((SW_Text*)widg)->fontid = val;
22664 break;
22665 case widgTEXTBOX:
22666 ((SW_TextBox*)widg)->fontid = val;
22667 break;
22668 case widgSELECTEDTEXT:
22669 ((SW_SelectedText*)widg)->fontid = val;
22670 break;
22671 case widgTIME:
22672 ((SW_Time*)widg)->fontid = val;
22673 break;
22674 case widgCOUNTER:
22675 ((SW_Counter*)widg)->fontid = val;
22676 break;
22677 case widgBTNCOUNTER:
22678 ((SW_BtnCounter*)widg)->fontid = val;
22679 break;
22680 case widgOLDCTR:
22681 ((SW_Counters*)widg)->fontid = val;
22682 break;
22683 case widgMMAPTITLE:
22684 ((SW_MMapTitle*)widg)->fontid = val;
22685 break;
22686 default:
22687 bad_subwidg_type(false, ty);
22688 break;
22689 }
22690 }
22691 break;
22692 }
22693 case SUBWIDGTY_ALIGN:
22694 {
22695 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22696 {
22697 auto val = vbound(value/10000,0,sstaMAX-1);
22698 auto ty = widg->getType();
22699 switch(ty)
22700 {
22701 case widgTEXT:
22702 ((SW_Text*)widg)->align = val;
22703 break;
22704 case widgTEXTBOX:
22705 ((SW_TextBox*)widg)->align = val;
22706 break;
22707 case widgSELECTEDTEXT:
22708 ((SW_SelectedText*)widg)->align = val;
22709 break;
22710 case widgTIME:
22711 ((SW_Time*)widg)->align = val;
22712 break;
22713 case widgCOUNTER:
22714 ((SW_Counter*)widg)->align = val;
22715 break;
22716 case widgBTNCOUNTER:
22717 ((SW_BtnCounter*)widg)->align = val;
22718 break;
22719 case widgMMAPTITLE:
22720 ((SW_MMapTitle*)widg)->align = val;
22721 break;
22722 default:
22723 bad_subwidg_type(false, ty);
22724 break;
22725 }
22726 }
22727 break;
22728 }
22729 case SUBWIDGTY_SHADOWTY:
22730 {
22731 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22732 {
22733 auto val = vbound(value/10000,0,sstsMAX-1);
22734 auto ty = widg->getType();
22735 switch(ty)
22736 {
22737 case widgTEXT:
22738 ((SW_Text*)widg)->shadtype = val;
22739 break;
22740 case widgTEXTBOX:
22741 ((SW_TextBox*)widg)->shadtype = val;
22742 break;
22743 case widgSELECTEDTEXT:
22744 ((SW_SelectedText*)widg)->shadtype = val;
22745 break;
22746 case widgTIME:
22747 ((SW_Time*)widg)->shadtype = val;
22748 break;
22749 case widgCOUNTER:
22750 ((SW_Counter*)widg)->shadtype = val;
22751 break;
22752 case widgBTNCOUNTER:
22753 ((SW_BtnCounter*)widg)->shadtype = val;
22754 break;
22755 case widgOLDCTR:
22756 ((SW_Counters*)widg)->shadtype = val;
22757 break;
22758 case widgMMAPTITLE:
22759 ((SW_MMapTitle*)widg)->shadtype = val;
22760 break;
22761 default:
22762 bad_subwidg_type(false, ty);
22763 break;
22764 }
22765 }
22766 break;
22767 }
22768 case SUBWIDGTY_COLOR_TXT:
22769 {
22770 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22771 {
22772 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
22773 auto ty = widg->getType();
22774 switch(ty)
22775 {
22776 case widgTEXT:
22777 ((SW_Text*)widg)->c_text.set_int_color(val);
22778 break;
22779 case widgTEXTBOX:
22780 ((SW_TextBox*)widg)->c_text.set_int_color(val);
22781 break;
22782 case widgSELECTEDTEXT:
22783 ((SW_SelectedText*)widg)->c_text.set_int_color(val);
22784 break;
22785 case widgTIME:
22786 ((SW_Time*)widg)->c_text.set_int_color(val);
22787 break;
22788 case widgCOUNTER:
22789 ((SW_Counter*)widg)->c_text.set_int_color(val);
22790 break;
22791 case widgBTNCOUNTER:
22792 ((SW_BtnCounter*)widg)->c_text.set_int_color(val);
22793 break;
22794 case widgOLDCTR:
22795 ((SW_Counters*)widg)->c_text.set_int_color(val);
22796 break;
22797 case widgMMAPTITLE:
22798 ((SW_MMapTitle*)widg)->c_text.set_int_color(val);
22799 break;
22800 case widgMCGUFF_FRAME:
22801 ((SW_TriFrame*)widg)->c_number.set_int_color(val);
22802 break;
22803 default:
22804 bad_subwidg_type(false, ty);
22805 break;
22806 }
22807 }
22808 break;
22809 }
22810 case SUBWIDGTY_COLOR_SHD:
22811 {
22812 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22813 {
22814 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
22815 auto ty = widg->getType();
22816 switch(ty)
22817 {
22818 case widgTEXT:
22819 ((SW_Text*)widg)->c_shadow.set_int_color(val);
22820 break;
22821 case widgTEXTBOX:
22822 ((SW_TextBox*)widg)->c_shadow.set_int_color(val);
22823 break;
22824 case widgSELECTEDTEXT:
22825 ((SW_SelectedText*)widg)->c_shadow.set_int_color(val);
22826 break;
22827 case widgTIME:
22828 ((SW_Time*)widg)->c_shadow.set_int_color(val);
22829 break;
22830 case widgCOUNTER:
22831 ((SW_Counter*)widg)->c_shadow.set_int_color(val);
22832 break;
22833 case widgBTNCOUNTER:
22834 ((SW_BtnCounter*)widg)->c_shadow.set_int_color(val);
22835 break;
22836 case widgOLDCTR:
22837 ((SW_Counters*)widg)->c_shadow.set_int_color(val);
22838 break;
22839 case widgMMAPTITLE:
22840 ((SW_MMapTitle*)widg)->c_shadow.set_int_color(val);
22841 break;
22842 default:
22843 bad_subwidg_type(false, ty);
22844 break;
22845 }
22846 }
22847 break;
22848 }
22849 case SUBWIDGTY_COLOR_BG:
22850 {
22851 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22852 {
22853 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
22854 auto ty = widg->getType();
22855 switch(ty)
22856 {
22857 case widgTEXT:
22858 ((SW_Text*)widg)->c_bg.set_int_color(val);
22859 break;
22860 case widgTEXTBOX:
22861 ((SW_TextBox*)widg)->c_bg.set_int_color(val);;
22862 break;
22863 case widgSELECTEDTEXT:
22864 ((SW_SelectedText*)widg)->c_bg.set_int_color(val);;
22865 break;
22866 case widgTIME:
22867 ((SW_Time*)widg)->c_bg.set_int_color(val);
22868 break;
22869 case widgCOUNTER:
22870 ((SW_Counter*)widg)->c_bg.set_int_color(val);
22871 break;
22872 case widgBTNCOUNTER:
22873 ((SW_BtnCounter*)widg)->c_bg.set_int_color(val);
22874 break;
22875 case widgOLDCTR:
22876 ((SW_Counters*)widg)->c_bg.set_int_color(val);
22877 break;
22878 case widgMMAPTITLE:
22879 ((SW_MMapTitle*)widg)->c_bg.set_int_color(val);
22880 break;
22881 case widgBGCOLOR:
22882 ((SW_Clear*)widg)->c_bg.set_int_color(val);
22883 break;
22884 case widgCOUNTERPERCBAR:
22885 ((SW_CounterPercentBar*)widg)->c_bg.set_int_color(val);
22886 break;
22887 default:
22888 bad_subwidg_type(false, ty);
22889 break;
22890 }
22891 }
22892 break;
22893 }
22894
22895 case SUBWIDGTY_COLOR_TXT2:
22896 {
22897 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22898 {
22899 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
22900 auto ty = widg->getType();
22901 switch(ty)
22902 {
22903 case widgCOUNTER:
22904 ((SW_Counter*)widg)->c_text2.set_int_color(val);
22905 break;
22906 case widgBTNCOUNTER:
22907 ((SW_BtnCounter*)widg)->c_text2.set_int_color(val);
22908 break;
22909 default:
22910 bad_subwidg_type(false, ty);
22911 break;
22912 }
22913 }
22914 break;
22915 }
22916 case SUBWIDGTY_COLOR_SHD2:
22917 {
22918 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22919 {
22920 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
22921 auto ty = widg->getType();
22922 switch(ty)
22923 {
22924 case widgCOUNTER:
22925 ((SW_Counter*)widg)->c_shadow2.set_int_color(val);
22926 break;
22927 case widgBTNCOUNTER:
22928 ((SW_BtnCounter*)widg)->c_shadow2.set_int_color(val);
22929 break;
22930 default:
22931 bad_subwidg_type(false, ty);
22932 break;
22933 }
22934 }
22935 break;
22936 }
22937 case SUBWIDGTY_COLOR_BG2:
22938 {
22939 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22940 {
22941 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
22942 auto ty = widg->getType();
22943 switch(ty)
22944 {
22945 case widgCOUNTER:
22946 ((SW_Counter*)widg)->c_bg2.set_int_color(val);
22947 break;
22948 case widgBTNCOUNTER:
22949 ((SW_BtnCounter*)widg)->c_bg2.set_int_color(val);
22950 break;
22951 default:
22952 bad_subwidg_type(false, ty);
22953 break;
22954 }
22955 }
22956 break;
22957 }
22958
22959 case SUBWIDGTY_COLOR_OLINE:
22960 {
22961 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22962 {
22963 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
22964 auto ty = widg->getType();
22965 switch(ty)
22966 {
22967 case widgLINE:
22968 ((SW_Line*)widg)->c_line.set_int_color(val);
22969 break;
22970 case widgRECT:
22971 ((SW_Rect*)widg)->c_outline.set_int_color(val);
22972 break;
22973 case widgMCGUFF_FRAME:
22974 ((SW_TriFrame*)widg)->c_outline.set_int_color(val);
22975 break;
22976 default:
22977 bad_subwidg_type(false, ty);
22978 break;
22979 }
22980 }
22981 break;
22982 }
22983
22984 case SUBWIDGTY_COLOR_FILL:
22985 {
22986 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
22987 {
22988 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
22989 auto ty = widg->getType();
22990 switch(ty)
22991 {
22992 case widgRECT:
22993 ((SW_Rect*)widg)->c_fill.set_int_color(val);
22994 break;
22995 case widgCOUNTERPERCBAR:
22996 ((SW_CounterPercentBar*)widg)->c_fill.set_int_color(val);
22997 break;
22998 default:
22999 bad_subwidg_type(false, ty);
23000 break;
23001 }
23002 }
23003 break;
23004 }
23005 case SUBWIDGTY_BUTTON:
23006 {
23007 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23008 {
23009 auto val = vbound(value/10000,0,3);
23010 auto ty = widg->getType();
23011 switch(ty)
23012 {
23013 case widgBTNITM:
23014 ((SW_ButtonItem*)widg)->btn = val;
23015 break;
23016 case widgBTNCOUNTER:
23017 ((SW_BtnCounter*)widg)->btn = val;
23018 break;
23019 default:
23020 bad_subwidg_type(false, ty);
23021 break;
23022 }
23023 }
23024 break;
23025 }
23026 case SUBWIDGTY_COUNTERS:
23027 {
23028 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23029 {
23030 auto val = vbound(value/10000,sscMIN+1,MAX_COUNTERS-1);
23031 size_t indx = ri->d[rINDEX]/10000;
23032 size_t sz = 0;
23033 byte ty = widg->getType();
23034 switch(ty)
23035 {
23036 case widgCOUNTER:
23037 sz = 3;
23038 break;
23039 case widgMISCGAUGE:
23040 sz = 1;
23041 break;
23042 default:
23043 sz = 0;
23044 bad_subwidg_type(false, ty);
23045 break;
23046 }
23047 if(!sz) break;
23048 if(indx >= sz)
23049 {
23050 Z_scripterrlog("Bad index '%d' to array "
23051 "'subscreenwidget->Counter[%d]'\n", indx, sz);
23052 break;
23053 }
23054 switch(ty)
23055 {
23056 case widgCOUNTER:
23057 ((SW_Counter*)widg)->ctrs[indx] = val;
23058 break;
23059 case widgMISCGAUGE:
23060 ((SW_MiscGaugePiece*)widg)->counter = val;
23061 break;
23062 }
23063 }
23064 break;
23065 }
23066 case SUBWIDGTY_MINDIG:
23067 {
23068 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23069 {
23070 auto val = vbound(value/10000,0,5);
23071 auto ty = widg->getType();
23072 switch(ty)
23073 {
23074 case widgCOUNTER:
23075 ((SW_Counter*)widg)->mindigits = val;
23076 break;
23077 case widgBTNCOUNTER:
23078 ((SW_BtnCounter*)widg)->mindigits = val;
23079 break;
23080 case widgOLDCTR:
23081 ((SW_Counters*)widg)->digits = val;
23082 break;
23083 default:
23084 bad_subwidg_type(false, ty);
23085 break;
23086 }
23087 }
23088 break;
23089 }
23090 case SUBWIDGTY_MAXDIG:
23091 {
23092 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23093 {
23094 auto val = vbound(value/10000,0,5);
23095 auto ty = widg->getType();
23096 switch(ty)
23097 {
23098 case widgCOUNTER:
23099 ((SW_Counter*)widg)->maxdigits = val;
23100 break;
23101 case widgBTNCOUNTER:
23102 ((SW_BtnCounter*)widg)->maxdigits = val;
23103 break;
23104 default:
23105 bad_subwidg_type(false, ty);
23106 break;
23107 }
23108 }
23109 break;
23110 }
23111 case SUBWIDGTY_INFITM:
23112 {
23113 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23114 {
23115 auto val = vbound(value/10000,-1,MAXITEMS-1);
23116 auto ty = widg->getType();
23117 switch(ty)
23118 {
23119 case widgCOUNTER:
23120 ((SW_Counter*)widg)->infitm = val;
23121 break;
23122 case widgOLDCTR:
23123 ((SW_Counters*)widg)->infitm = val;
23124 break;
23125 case widgLGAUGE:
23126 case widgMGAUGE:
23127 case widgMISCGAUGE:
23128 ((SW_GaugePiece*)widg)->inf_item = val;
23129 break;
23130 default:
23131 bad_subwidg_type(false, ty);
23132 break;
23133 }
23134 }
23135 break;
23136 }
23137 case SUBWIDGTY_INFCHAR:
23138 {
23139 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23140 {
23141 char val = vbound(value/10000,0,255);
23142 auto ty = widg->getType();
23143 switch(ty)
23144 {
23145 case widgCOUNTER:
23146 ((SW_Counter*)widg)->infchar = val;
23147 break;
23148 case widgBTNCOUNTER:
23149 ((SW_BtnCounter*)widg)->infchar = val;
23150 break;
23151 case widgOLDCTR:
23152 ((SW_Counters*)widg)->infchar = val;
23153 break;
23154 default:
23155 bad_subwidg_type(false, ty);
23156 break;
23157 }
23158 }
23159 break;
23160 }
23161 case SUBWIDGTY_COSTIND:
23162 {
23163 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23164 {
23165 auto val = vbound(value/10000,0,1);
23166 auto ty = widg->getType();
23167 switch(ty)
23168 {
23169 case widgBTNCOUNTER:
23170 ((SW_BtnCounter*)widg)->costind = val;
23171 break;
23172 default:
23173 bad_subwidg_type(false, ty);
23174 break;
23175 }
23176 }
23177 break;
23178 }
23179 case SUBWIDGTY_COLOR_PLAYER:
23180 {
23181 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23182 {
23183 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
23184 auto ty = widg->getType();
23185 switch(ty)
23186 {
23187 case widgMMAP:
23188 ((SW_MMap*)widg)->c_plr.set_int_color(val);
23189 break;
23190 case widgLMAP:
23191 ((SW_LMap*)widg)->c_plr.set_int_color(val);
23192 break;
23193 default:
23194 bad_subwidg_type(false, ty);
23195 break;
23196 }
23197 }
23198 break;
23199 }
23200 case SUBWIDGTY_COLOR_CMPBLNK:
23201 {
23202 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23203 {
23204 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
23205 auto ty = widg->getType();
23206 switch(ty)
23207 {
23208 case widgMMAP:
23209 ((SW_MMap*)widg)->c_cmp_blink.set_int_color(val);
23210 break;
23211 default:
23212 bad_subwidg_type(false, ty);
23213 break;
23214 }
23215 }
23216 break;
23217 }
23218 case SUBWIDGTY_COLOR_CMPOFF:
23219 {
23220 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23221 {
23222 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
23223 auto ty = widg->getType();
23224 switch(ty)
23225 {
23226 case widgMMAP:
23227 ((SW_MMap*)widg)->c_cmp_off.set_int_color(val);
23228 break;
23229 default:
23230 bad_subwidg_type(false, ty);
23231 break;
23232 }
23233 }
23234 break;
23235 }
23236 case SUBWIDGTY_COLOR_ROOM:
23237 {
23238 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23239 {
23240 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
23241 auto ty = widg->getType();
23242 switch(ty)
23243 {
23244 case widgLMAP:
23245 ((SW_LMap*)widg)->c_room.set_int_color(val);
23246 break;
23247 default:
23248 bad_subwidg_type(false, ty);
23249 break;
23250 }
23251 }
23252 break;
23253 }
23254 case SUBWIDGTY_ITEMCLASS:
23255 {
23256 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23257 {
23258 auto val = vbound(value/10000,0,itype_maxusable-1);
23259 auto ty = widg->getType();
23260 switch(ty)
23261 {
23262 case widgITEMSLOT:
23263 ((SW_ItemSlot*)widg)->iclass = val;
23264 break;
23265 default:
23266 bad_subwidg_type(false, ty);
23267 break;
23268 }
23269 }
23270 break;
23271 }
23272 case SUBWIDGTY_ITEMID:
23273 {
23274 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23275 {
23276 auto val = vbound(value/10000,-1,MAXITEMS-1);
23277 auto ty = widg->getType();
23278 switch(ty)
23279 {
23280 case widgITEMSLOT:
23281 ((SW_ItemSlot*)widg)->iid = val;
23282 break;
23283 default:
23284 bad_subwidg_type(false, ty);
23285 break;
23286 }
23287 }
23288 break;
23289 }
23290 case SUBWIDGTY_FRAMETILE:
23291 {
23292 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23293 {
23294 auto val = vbound(value/10000,0,NEWMAXTILES-1);
23295 auto ty = widg->getType();
23296 switch(ty)
23297 {
23298 case widgMCGUFF_FRAME:
23299 ((SW_TriFrame*)widg)->frame_tile = val;
23300 break;
23301 default:
23302 bad_subwidg_type(false, ty);
23303 break;
23304 }
23305 }
23306 break;
23307 }
23308 case SUBWIDGTY_FRAMECSET:
23309 {
23310 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23311 {
23312 auto val = vbound(value/10000,0,15);
23313 auto ty = widg->getType();
23314 switch(ty)
23315 {
23316 case widgMCGUFF_FRAME:
23317 ((SW_TriFrame*)widg)->frame_cset = val;
23318 break;
23319 default:
23320 bad_subwidg_type(false, ty);
23321 break;
23322 }
23323 }
23324 break;
23325 }
23326 case SUBWIDGTY_PIECETILE:
23327 {
23328 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23329 {
23330 auto val = vbound(value/10000,0,NEWMAXTILES-1);
23331 auto ty = widg->getType();
23332 switch(ty)
23333 {
23334 case widgMCGUFF_FRAME:
23335 ((SW_TriFrame*)widg)->piece_tile = val;
23336 break;
23337 default:
23338 bad_subwidg_type(false, ty);
23339 break;
23340 }
23341 }
23342 break;
23343 }
23344 case SUBWIDGTY_PIECECSET:
23345 {
23346 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23347 {
23348 auto val = vbound(value/10000,0,15);
23349 auto ty = widg->getType();
23350 switch(ty)
23351 {
23352 case widgMCGUFF_FRAME:
23353 ((SW_TriFrame*)widg)->piece_cset = val;
23354 break;
23355 default:
23356 bad_subwidg_type(false, ty);
23357 break;
23358 }
23359 }
23360 break;
23361 }
23362 case SUBWIDGTY_FLIP:
23363 {
23364 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23365 {
23366 auto val = vbound(value/10000,0,15);
23367 auto ty = widg->getType();
23368 switch(ty)
23369 {
23370 case widgMCGUFF:
23371 ((SW_McGuffin*)widg)->flip = val;
23372 break;
23373 case widgTILEBLOCK:
23374 ((SW_TileBlock*)widg)->flip = val;
23375 break;
23376 case widgMINITILE:
23377 ((SW_MiniTile*)widg)->flip = val;
23378 break;
23379 default:
23380 bad_subwidg_type(false, ty);
23381 break;
23382 }
23383 }
23384 break;
23385 }
23386 case SUBWIDGTY_NUMBER:
23387 {
23388 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23389 {
23390 auto val = vbound(value/10000,0,255);
23391 auto ty = widg->getType();
23392 switch(ty)
23393 {
23394 case widgMCGUFF:
23395 ((SW_McGuffin*)widg)->number = val;
23396 break;
23397 default:
23398 bad_subwidg_type(false, ty);
23399 break;
23400 }
23401 }
23402 break;
23403 }
23404 case SUBWIDGTY_CORNER:
23405 {
23406 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23407 {
23408 auto val = vbound(value/10000,0,3);
23409 size_t indx = ri->d[rINDEX]/10000;
23410 size_t sz = 0;
23411 byte ty = widg->getType();
23412 switch(ty)
23413 {
23414 case widgMINITILE:
23415 sz = 1;
23416 break;
23417 case widgLGAUGE:
23418 case widgMGAUGE:
23419 case widgMISCGAUGE:
23420 sz = 4;
23421 break;
23422 default:
23423 sz = 0;
23424 bad_subwidg_type(false, ty);
23425 break;
23426 }
23427 if(!sz) break;
23428 if(indx >= sz)
23429 {
23430 Z_scripterrlog("Bad index '%d' to array "
23431 "'subscreenwidget->Corner[%d]'\n", indx, sz);
23432 break;
23433 }
23434 switch(ty)
23435 {
23436 case widgMINITILE:
23437 ((SW_MiniTile*)widg)->crn = val;
23438 break;
23439 case widgLGAUGE:
23440 case widgMGAUGE:
23441 case widgMISCGAUGE:
23442 ((SW_GaugePiece*)widg)->mts[indx].setCrn(val);
23443 break;
23444 }
23445 }
23446 break;
23447 }
23448 case SUBWIDGTY_FRAMES:
23449 {
23450 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23451 {
23452 auto val = vbound(value/10000,1,65535);
23453 auto ty = widg->getType();
23454 switch(ty)
23455 {
23456 case widgLGAUGE:
23457 case widgMGAUGE:
23458 case widgMISCGAUGE:
23459 ((SW_GaugePiece*)widg)->frames = val;
23460 break;
23461 default:
23462 bad_subwidg_type(false, ty);
23463 break;
23464 }
23465 }
23466 break;
23467 }
23468 case SUBWIDGTY_SPEED:
23469 {
23470 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23471 {
23472 auto val = vbound(value/10000,1,65535);
23473 auto ty = widg->getType();
23474 switch(ty)
23475 {
23476 case widgLGAUGE:
23477 case widgMGAUGE:
23478 case widgMISCGAUGE:
23479 ((SW_GaugePiece*)widg)->speed = val;
23480 break;
23481 default:
23482 bad_subwidg_type(false, ty);
23483 break;
23484 }
23485 }
23486 break;
23487 }
23488 case SUBWIDGTY_DELAY:
23489 {
23490 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23491 {
23492 auto val = vbound(value/10000,0,65535);
23493 auto ty = widg->getType();
23494 switch(ty)
23495 {
23496 case widgLGAUGE:
23497 case widgMGAUGE:
23498 case widgMISCGAUGE:
23499 ((SW_GaugePiece*)widg)->delay = val;
23500 break;
23501 default:
23502 bad_subwidg_type(false, ty);
23503 break;
23504 }
23505 }
23506 break;
23507 }
23508 case SUBWIDGTY_CONTAINER:
23509 {
23510 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23511 {
23512 auto val = vbound(value/10000,0,65535);
23513 auto ty = widg->getType();
23514 switch(ty)
23515 {
23516 case widgLGAUGE:
23517 case widgMGAUGE:
23518 case widgMISCGAUGE:
23519 ((SW_GaugePiece*)widg)->container = val;
23520 break;
23521 default:
23522 bad_subwidg_type(false, ty);
23523 break;
23524 }
23525 }
23526 break;
23527 }
23528 case SUBWIDGTY_GAUGE_WID:
23529 {
23530 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23531 {
23532 auto val = vbound(value/10000,1,32)-1;
23533 auto ty = widg->getType();
23534 switch(ty)
23535 {
23536 case widgLGAUGE:
23537 case widgMGAUGE:
23538 case widgMISCGAUGE:
23539 ((SW_GaugePiece*)widg)->gauge_wid = val;
23540 break;
23541 default:
23542 bad_subwidg_type(false, ty);
23543 break;
23544 }
23545 }
23546 break;
23547 }
23548 case SUBWIDGTY_GAUGE_HEI:
23549 {
23550 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23551 {
23552 auto val = vbound(value/10000,1,32)-1;
23553 auto ty = widg->getType();
23554 switch(ty)
23555 {
23556 case widgLGAUGE:
23557 case widgMGAUGE:
23558 case widgMISCGAUGE:
23559 ((SW_GaugePiece*)widg)->gauge_hei = val;
23560 break;
23561 default:
23562 bad_subwidg_type(false, ty);
23563 break;
23564 }
23565 }
23566 break;
23567 }
23568 case SUBWIDGTY_UNITS:
23569 {
23570 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23571 {
23572 auto val = vbound(value/10000,1,256);
23573 auto ty = widg->getType();
23574 switch(ty)
23575 {
23576 case widgLGAUGE:
23577 case widgMGAUGE:
23578 case widgMISCGAUGE:
23579 ((SW_GaugePiece*)widg)->unit_per_frame = val-1;
23580 break;
23581 default:
23582 bad_subwidg_type(false, ty);
23583 break;
23584 }
23585 }
23586 break;
23587 }
23588 case SUBWIDGTY_HSPACE:
23589 {
23590 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23591 {
23592 auto val = vbound(value/10000,-128,127);
23593 auto ty = widg->getType();
23594 switch(ty)
23595 {
23596 case widgLGAUGE:
23597 case widgMGAUGE:
23598 case widgMISCGAUGE:
23599 ((SW_GaugePiece*)widg)->hspace = val;
23600 break;
23601 default:
23602 bad_subwidg_type(false, ty);
23603 break;
23604 }
23605 }
23606 break;
23607 }
23608 case SUBWIDGTY_VSPACE:
23609 {
23610 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23611 {
23612 auto val = vbound(value/10000,-128,127);
23613 auto ty = widg->getType();
23614 switch(ty)
23615 {
23616 case widgLGAUGE:
23617 case widgMGAUGE:
23618 case widgMISCGAUGE:
23619 ((SW_GaugePiece*)widg)->vspace = val;
23620 break;
23621 default:
23622 bad_subwidg_type(false, ty);
23623 break;
23624 }
23625 }
23626 break;
23627 }
23628 case SUBWIDGTY_GRIDX:
23629 {
23630 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23631 {
23632 auto val = vbound(value/10000,-32768,32767);
23633 auto ty = widg->getType();
23634 switch(ty)
23635 {
23636 case widgLGAUGE:
23637 case widgMGAUGE:
23638 case widgMISCGAUGE:
23639 ((SW_GaugePiece*)widg)->grid_xoff = val;
23640 break;
23641 default:
23642 bad_subwidg_type(false, ty);
23643 break;
23644 }
23645 }
23646 break;
23647 }
23648 case SUBWIDGTY_GRIDY:
23649 {
23650 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23651 {
23652 auto val = vbound(value/10000,-32768,32767);
23653 auto ty = widg->getType();
23654 switch(ty)
23655 {
23656 case widgLGAUGE:
23657 case widgMGAUGE:
23658 case widgMISCGAUGE:
23659 ((SW_GaugePiece*)widg)->grid_yoff = val;
23660 break;
23661 default:
23662 bad_subwidg_type(false, ty);
23663 break;
23664 }
23665 }
23666 break;
23667 }
23668 case SUBWIDGTY_ANIMVAL:
23669 {
23670 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23671 {
23672 auto val = vbound(value/10000,0,65535);
23673 auto ty = widg->getType();
23674 switch(ty)
23675 {
23676 case widgLGAUGE:
23677 case widgMGAUGE:
23678 case widgMISCGAUGE:
23679 ((SW_GaugePiece*)widg)->anim_val = val;
23680 break;
23681 default:
23682 bad_subwidg_type(false, ty);
23683 break;
23684 }
23685 }
23686 break;
23687 }
23688 case SUBWIDGTY_SHOWDRAIN:
23689 {
23690 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23691 {
23692 auto val = vbound(value/10000,-1,32767);
23693 auto ty = widg->getType();
23694 switch(ty)
23695 {
23696 case widgMGAUGE:
23697 ((SW_MagicGaugePiece*)widg)->showdrain = val;
23698 break;
23699 default:
23700 bad_subwidg_type(false, ty);
23701 break;
23702 }
23703 }
23704 break;
23705 }
23706 case SUBWIDGTY_PERCONTAINER:
23707 {
23708 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23709 {
23710 auto val = vbound(value/10000,1,65535);
23711 auto ty = widg->getType();
23712 switch(ty)
23713 {
23714 case widgMISCGAUGE:
23715 ((SW_MiscGaugePiece*)widg)->per_container = val;
23716 break;
23717 default:
23718 bad_subwidg_type(false, ty);
23719 break;
23720 }
23721 }
23722 break;
23723 }
23724 case SUBWIDGTY_TABSIZE:
23725 {
23726 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23727 {
23728 auto val = vbound(value/10000,0,255);
23729 auto ty = widg->getType();
23730 switch(ty)
23731 {
23732 case widgTEXTBOX:
23733 ((SW_TextBox*)widg)->tabsize = val;
23734 break;
23735 case widgSELECTEDTEXT:
23736 ((SW_SelectedText*)widg)->tabsize = val;
23737 break;
23738 default:
23739 bad_subwidg_type(false, ty);
23740 break;
23741 }
23742 }
23743 break;
23744 }
23745 case SUBWIDGTY_LITEMS:
23746 {
23747 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
23748 {
23749 auto val = vbound(value/10000,0,255);
23750 auto ty = widg->getType();
23751 switch(ty)
23752 {
23753 case widgMMAP:
23754 ((SW_MMap*)widg)->compass_litems = val;
23755 break;
23756 default:
23757 bad_subwidg_type(false, ty);
23758 break;
23759 }
23760 }
23761 break;
23762 }
23763 ///----------------------------------------------------------------------------------------------------//
23764
23765 default:
23766 35323033 scripting_engine_set_register(arg, value);
23767 35323033 }
23768
23769 1622644924 current_zasm_register = 0;
23770 2111482080 } //end set_register
23771
23772 403 static std::map<std::string, int> name_to_slot_index_ffcmap;
23773 403 static std::map<std::string, int> name_to_slot_index_globalmap;
23774 403 static std::map<std::string, int> name_to_slot_index_genericmap;
23775 403 static std::map<std::string, int> name_to_slot_index_itemmap;
23776 403 static std::map<std::string, int> name_to_slot_index_npcmap;
23777 403 static std::map<std::string, int> name_to_slot_index_ewpnmap;
23778 403 static std::map<std::string, int> name_to_slot_index_lwpnmap;
23779 403 static std::map<std::string, int> name_to_slot_index_playermap;
23780 403 static std::map<std::string, int> name_to_slot_index_dmapmap;
23781 403 static std::map<std::string, int> name_to_slot_index_screenmap;
23782 403 static std::map<std::string, int> name_to_slot_index_itemspritemap;
23783 403 static std::map<std::string, int> name_to_slot_index_comboscriptmap;
23784 403 static std::map<std::string, int> name_to_slot_index_subscreenmap;
23785
23786 413 void script_init_name_to_slot_index_maps()
23787 {
23788 int i;
23789 #define DECL_INIT_MAP(name) \
23790 {\
23791 name_to_slot_index_##name.clear();\
23792 i = 0;\
23793 for (auto& it : name)\
23794 {\
23795 if (!name_to_slot_index_##name.contains(it.second.scriptname))\
23796 name_to_slot_index_##name[it.second.scriptname] = i;\
23797 i++;\
23798 }\
23799 }
23800
23801
4/4
✓ Branch 0 taken 211043 times.
✓ Branch 1 taken 413 times.
✓ Branch 2 taken 201899 times.
✓ Branch 3 taken 9144 times.
211456 DECL_INIT_MAP(ffcmap);
23802
4/4
✓ Branch 0 taken 3304 times.
✓ Branch 1 taken 413 times.
✓ Branch 2 taken 1913 times.
✓ Branch 3 taken 1391 times.
3717 DECL_INIT_MAP(globalmap);
23803
4/4
✓ Branch 0 taken 211043 times.
✓ Branch 1 taken 413 times.
✓ Branch 2 taken 209150 times.
✓ Branch 3 taken 1893 times.
211456 DECL_INIT_MAP(genericmap);
23804
4/4
✓ Branch 0 taken 105315 times.
✓ Branch 1 taken 413 times.
✓ Branch 2 taken 103775 times.
✓ Branch 3 taken 1540 times.
105728 DECL_INIT_MAP(itemmap);
23805
4/4
✓ Branch 0 taken 105315 times.
✓ Branch 1 taken 413 times.
✓ Branch 2 taken 104883 times.
✓ Branch 3 taken 432 times.
105728 DECL_INIT_MAP(npcmap);
23806
4/4
✓ Branch 0 taken 105315 times.
✓ Branch 1 taken 413 times.
✓ Branch 2 taken 104699 times.
✓ Branch 3 taken 616 times.
105728 DECL_INIT_MAP(ewpnmap);
23807
4/4
✓ Branch 0 taken 105315 times.
✓ Branch 1 taken 413 times.
✓ Branch 2 taken 104650 times.
✓ Branch 3 taken 665 times.
105728 DECL_INIT_MAP(lwpnmap);
23808
4/4
✓ Branch 0 taken 1652 times.
✓ Branch 1 taken 413 times.
✓ Branch 2 taken 1224 times.
✓ Branch 3 taken 428 times.
2065 DECL_INIT_MAP(playermap);
23809
4/4
✓ Branch 0 taken 105315 times.
✓ Branch 1 taken 413 times.
✓ Branch 2 taken 104518 times.
✓ Branch 3 taken 797 times.
105728 DECL_INIT_MAP(dmapmap);
23810
4/4
✓ Branch 0 taken 105315 times.
✓ Branch 1 taken 413 times.
✓ Branch 2 taken 104576 times.
✓ Branch 3 taken 739 times.
105728 DECL_INIT_MAP(screenmap);
23811
4/4
✓ Branch 0 taken 105315 times.
✓ Branch 1 taken 413 times.
✓ Branch 2 taken 104868 times.
✓ Branch 3 taken 447 times.
105728 DECL_INIT_MAP(itemspritemap);
23812
4/4
✓ Branch 0 taken 211043 times.
✓ Branch 1 taken 413 times.
✓ Branch 2 taken 210518 times.
✓ Branch 3 taken 525 times.
211456 DECL_INIT_MAP(comboscriptmap);
23813
4/4
✓ Branch 0 taken 105315 times.
✓ Branch 1 taken 413 times.
✓ Branch 2 taken 104896 times.
✓ Branch 3 taken 419 times.
105728 DECL_INIT_MAP(subscreenmap);
23814 413 }
23815
23816 10246312 static void do_get_script_index_by_name(const std::map<std::string, int>& name_to_slot_index)
23817 {
23818 10246312 int32_t arrayptr = get_register(sarg1) / 10000;
23819 10246312 string name;
23820 10246312 int32_t num=-1;
23821
1/2
✓ Branch 0 taken 10246312 times.
✗ Branch 1 not taken.
10246312 ArrayH::getString(arrayptr, name, 256); // What's the limit on name length?
23822
23823
1/2
✓ Branch 0 taken 10246312 times.
✗ Branch 1 not taken.
10246312 auto it = name_to_slot_index.find(name);
23824
2/2
✓ Branch 0 taken 8430579 times.
✓ Branch 1 taken 1815733 times.
10246312 if (it != name_to_slot_index.end())
23825 1815733 num = it->second + 1;
23826
23827
1/2
✓ Branch 0 taken 10246312 times.
✗ Branch 1 not taken.
10246312 set_register(sarg1, num * 10000);
23828 10246312 }
23829
23830 int32_t get_int_arr(const int32_t ptr, int32_t indx)
23831 {
23832 switch(ptr)
23833 {
23834 case INTARR_SCREEN_NPC:
23835 {
23836 current_zasm_context = "Screen->NPCs[]";
23837 if(BC::checkGuyIndex(indx) != SH::_NoError)
23838 return 0;
23839 current_zasm_context = "";
23840
23841 return guys.spr(indx)->getUID();
23842 }
23843 case INTARR_SCREEN_ITEMSPR:
23844 {
23845 current_zasm_context = "Screen->Items[]";
23846 if(BC::checkItemIndex(indx) != SH::_NoError)
23847 return 0;
23848 current_zasm_context = "";
23849
23850 return items.spr(indx)->getUID();
23851 }
23852 case INTARR_SCREEN_LWPN:
23853 {
23854 current_zasm_context = "Screen->LWeapons[]";
23855 if(BC::checkLWeaponIndex(indx) != SH::_NoError)
23856 return 0;
23857 current_zasm_context = "";
23858
23859 return Lwpns.spr(indx)->getUID();
23860 }
23861 case INTARR_SCREEN_EWPN:
23862 {
23863 current_zasm_context = "Screen->EWeapons[]";
23864 if(BC::checkEWeaponIndex(indx) != SH::_NoError)
23865 return 0;
23866 current_zasm_context = "";
23867
23868 return Ewpns.spr(indx)->getUID();
23869 }
23870 case INTARR_SCREEN_FFC:
23871 {
23872 current_zasm_context = "Screen->FFCs[]";
23873 if (auto ffc = ResolveFFCWithID(indx))
23874 {
23875 current_zasm_context = "";
23876
23877 if (ZScriptVersion::ffcRefIsSpriteId())
23878 return ffc->getUID();
23879
23880 return indx * 10000;
23881 }
23882
23883 return 0;
23884 }
23885 case INTARR_SCREEN_PORTALS:
23886 {
23887 current_zasm_context = "Screen->Portals[]";
23888 if(BC::checkBoundsOneIndexed(indx, 0, portals.Count()-1) != SH::_NoError)
23889 return 0;
23890 current_zasm_context = "";
23891
23892 return portals.spr(indx)->getUID();
23893 }
23894 case INTARR_SAVPRTL:
23895 {
23896 current_zasm_context = "Game->SavedPortals[]";
23897 if(BC::checkBoundsOneIndexed(indx, 0, game->user_portals.size()-1) != SH::_NoError)
23898 return 0;
23899 current_zasm_context = "";
23900
23901 return (indx+1)*10000;
23902 }
23903 default:
23904 {
23905 scripting_log_error_with_context("Unknown internal array '{}' read from!", ptr);
23906 return 0;
23907 }
23908 }
23909 }
23910 void set_int_arr(const int32_t ptr, int32_t indx, int32_t val)
23911 {
23912 switch(ptr)
23913 {
23914 case INTARR_SCREEN_NPC:
23915 scripting_log_error_with_context("Read-only array 'Screen->NPCs' cannot be written to!");
23916 return;
23917 case INTARR_SCREEN_ITEMSPR:
23918 scripting_log_error_with_context("Read-only array 'Screen->Items' cannot be written to!");
23919 return;
23920 case INTARR_SCREEN_LWPN:
23921 scripting_log_error_with_context("Read-only array 'Screen->LWeapons' cannot be written to!");
23922 return;
23923 case INTARR_SCREEN_EWPN:
23924 scripting_log_error_with_context("Read-only array 'Screen->EWeapons' cannot be written to!");
23925 return;
23926 case INTARR_SCREEN_FFC:
23927 scripting_log_error_with_context("Read-only array 'Screen->FFCs' cannot be written to!");
23928 return;
23929 case INTARR_SCREEN_PORTALS:
23930 scripting_log_error_with_context("Read-only array 'Screen->Portals' cannot be written to!");
23931 return;
23932 case INTARR_SAVPRTL:
23933 scripting_log_error_with_context("Read-only array 'Game->SavedPortals' cannot be written to!");
23934 return;
23935
23936 default:
23937 {
23938 scripting_log_error_with_context("Unknown internal array '{}' written to!", ptr);
23939 return;
23940 }
23941 }
23942 }
23943 int32_t sz_int_arr(const int32_t ptr)
23944 {
23945 switch(ptr)
23946 {
23947 case INTARR_SCREEN_NPC:
23948 {
23949 return guys.Count();
23950 }
23951 case INTARR_SCREEN_ITEMSPR:
23952 {
23953 return items.Count();
23954 }
23955 case INTARR_SCREEN_LWPN:
23956 {
23957 return Lwpns.Count();
23958 }
23959 case INTARR_SCREEN_EWPN:
23960 {
23961 return Ewpns.Count();
23962 }
23963 case INTARR_SCREEN_FFC:
23964 {
23965 return MAXFFCS;
23966 }
23967 case INTARR_SCREEN_PORTALS:
23968 {
23969 return portals.Count();
23970 }
23971 case INTARR_SAVPRTL:
23972 {
23973 return game->user_portals.size();
23974 }
23975 default:
23976 {
23977 scripting_log_error_with_context("Unknown internal array '{}' size read!", ptr);
23978 return -1;
23979 }
23980 }
23981 }
23982
23983 ///----------------------------------------------------------------------------------------------------//
23984 // ASM Functions //
23985 ///----------------------------------------------------------------------------------------------------//
23986
23987 65 void retstack_push(int32_t val)
23988 {
23989
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 65 times.
65 if(ri->retsp >= ret_stack->size())
23990 {
23991 scripting_log_error_with_context("RetStack over or underflow, retstack pointer = {}", ri->retsp);
23992 return;
23993 }
23994 65 ret_stack->at(ri->retsp++) = val;
23995 65 }
23996 185 optional<int32_t> retstack_pop()
23997 {
23998
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 65 times.
185 if(!ri->retsp)
23999 120 return nullopt; //return from root, so, QUIT
24000 65 return ret_stack->at(--ri->retsp);
24001 185 }
24002
24003 5836 void stack_push(int32_t val)
24004 {
24005 5836 --ri->sp;
24006 5836 ri->sp &= MASK_SP;
24007 5836 SH::write_stack(ri->sp, val);
24008 5836 }
24009 25 void stack_push(int32_t val, size_t count)
24010 {
24011
2/2
✓ Branch 0 taken 173 times.
✓ Branch 1 taken 25 times.
198 for(int q = 0; q < count; ++q)
24012 {
24013 173 --ri->sp;
24014 173 ri->sp &= MASK_SP;
24015 173 SH::write_stack(ri->sp, val);
24016 173 }
24017 25 }
24018
24019 5548 int32_t stack_pop()
24020 {
24021 5548 const int32_t val = SH::read_stack(ri->sp);
24022 5548 ++ri->sp;
24023 5548 ri->sp &= MASK_SP;
24024 5548 return val;
24025 }
24026 61 int32_t stack_pop(size_t count)
24027 {
24028 61 ri->sp += count;
24029 61 ri->sp &= MASK_SP;
24030 61 const int32_t val = SH::read_stack((ri->sp-1) & MASK_SP);
24031 61 return val;
24032 }
24033
24034 ///----------------------------------------------------------------------------------------------------//
24035 //Internal (to ZScript)
24036
24037 3918 void do_set(const bool v, ScriptType whichType, const int32_t whichUID)
24038 {
24039 3918 bool allowed = true;
24040
1/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 3918 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
3918 switch(whichType) //Check for objects attempting to change own script
24041 {
24042 //case ScriptType::Global:
24043
24044 case ScriptType::FFC:
24045 if (sarg1 == FFSCRIPT)
24046 {
24047 if (auto ffc = ResolveFFC(ri->ffcref); ffc && ffc->index == whichUID)
24048 allowed = false;
24049 }
24050 break;
24051
24052 case ScriptType::Screen:
24053 if(sarg1==SCREENSCRIPT) //Only 1 screen script running at a time, no UID check needed
24054 allowed = false;
24055 break;
24056
24057 case ScriptType::Item:
24058 {
24059 bool collect = ( ( whichUID < 1 ) || (whichUID == COLLECT_SCRIPT_ITEM_ZERO) );
24060 int32_t new_UID = ( collect ) ? (( whichUID != COLLECT_SCRIPT_ITEM_ZERO ) ? (whichUID * -1) : 0) : whichUID;
24061
24062 if(collect)
24063 {
24064 if(sarg1==IDATAPSCRIPT && ri->idata==new_UID)
24065 allowed = false;
24066 }
24067 else if(sarg1==IDATASCRIPT && ri->idata==new_UID)
24068 allowed = false;
24069 break;
24070 }
24071
24072 case ScriptType::Lwpn:
24073 if(sarg1==LWPNSCRIPT && ri->lwpn==whichUID)
24074 allowed = false;
24075 break;
24076
24077 case ScriptType::NPC:
24078 if(sarg1==NPCSCRIPT && ri->guyref==whichUID)
24079 allowed = false;
24080 break;
24081
24082 case ScriptType::Ewpn:
24083 if(sarg1==EWPNSCRIPT && ri->ewpn==whichUID)
24084 allowed = false;
24085 break;
24086
24087 case ScriptType::DMap:
24088 if(sarg1==DMAPSCRIPT && ri->dmapsref==whichUID)
24089 allowed = false;
24090 break;
24091
24092 case ScriptType::ItemSprite:
24093 if(sarg1==ITEMSPRITESCRIPT && ri->itemref==whichUID)
24094 allowed = false;
24095 break;
24096 }
24097
1/2
✓ Branch 0 taken 3918 times.
✗ Branch 1 not taken.
3918 if(!allowed)
24098 {
24099 Z_scripterrlog("Script attempted to change own object's script! This has been ignored.\n");
24100 return;
24101 }
24102 3918 int32_t temp = SH::get_arg(sarg2, v);
24103 3918 set_register(sarg1, temp);
24104 3918 }
24105
24106 5836 void do_push(const bool v)
24107 {
24108 5836 const int32_t value = SH::get_arg(sarg1, v);
24109 5836 stack_push(value);
24110 5836 }
24111 3381100 void do_push_varg(const bool v)
24112 {
24113 3381100 const int32_t value = SH::get_arg(sarg1, v);
24114 3381100 zs_vargs.push_back(value);
24115 3381100 }
24116
24117 2674 void do_push_vargs(const bool v)
24118 {
24119
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2674 times.
2674 if(sarg2 < 1) return;
24120 2674 const int value = SH::get_arg(sarg1, v);
24121 2674 zs_vargs.insert(zs_vargs.end(), sarg2, value);
24122 2674 zs_vargs.push_back(value);
24123 2674 }
24124
24125 5548 void do_pop()
24126 {
24127 5548 set_register(sarg1, stack_pop());
24128 5548 }
24129
24130 void do_peek()
24131 {
24132 set_register(sarg1, SH::read_stack(ri->sp));
24133 }
24134
24135 28 void do_peekat(const bool v)
24136 {
24137 28 auto offs = SH::get_arg(sarg2,v);
24138 28 set_register(sarg1, SH::read_stack(ri->sp+offs));
24139 28 }
24140
24141 void do_writeat(const bool v1, const bool v2)
24142 {
24143 auto val = SH::get_arg(sarg1,v1);
24144 auto offs = SH::get_arg(sarg2,v2);
24145 SH::write_stack(ri->sp+offs, val);
24146 }
24147
24148 61 void do_pops() // Pop past a bunch of stuff at once. Useful for clearing the stack.
24149 {
24150 61 set_register(sarg1, stack_pop(sarg2));
24151 61 }
24152
24153 25 void do_pushs(const bool v) // Push a bunch of the same thing. Useful for filling the stack.
24154 {
24155 25 const int value = SH::get_arg(sarg1, v);
24156 25 stack_push(value, sarg2);
24157 25 }
24158
24159 50 void do_loadi()
24160 {
24161 50 const int32_t stackoffset = get_register(sarg2) / 10000;
24162 50 const int32_t value = SH::read_stack(stackoffset);
24163 50 set_register(sarg1, value);
24164 50 }
24165
24166 8 void do_storei()
24167 {
24168 8 const int32_t stackoffset = get_register(sarg2) / 10000;
24169 8 const int32_t value = get_register(sarg1);
24170 8 SH::write_stack(stackoffset, value);
24171 8 }
24172
24173 void do_loadd()
24174 {
24175 const int32_t stackoffset = (sarg2+ri->d[rSFRAME]) / 10000;
24176 const int32_t value = SH::read_stack(stackoffset);
24177 set_register(sarg1, value);
24178 }
24179
24180 6044 void do_load()
24181 {
24182 6044 const int32_t stackoffset = ri->d[rSFRAME] + sarg2;
24183 6044 const int32_t value = SH::read_stack(stackoffset);
24184 6044 set_register(sarg1, value);
24185 6044 }
24186
24187 void do_stored(const bool v)
24188 {
24189 const int32_t stackoffset = (sarg2+ri->d[rSFRAME]) / 10000;
24190 const int32_t value = SH::get_arg(sarg1, v);
24191 SH::write_stack(stackoffset, value);
24192 }
24193
24194 2162 void do_store(const bool v)
24195 {
24196 2162 const int32_t stackoffset = ri->d[rSFRAME] + sarg2;
24197 2162 const int32_t value = SH::get_arg(sarg1, v);
24198 2162 SH::write_stack(stackoffset, value);
24199 2162 }
24200
24201 756 void script_store_object(uint32_t offset, uint32_t new_id)
24202 {
24203 // Increase, then decrease, to handle the case where a variable (holding the only reference to an object) is assigned to itself.
24204 // This is unlikely so lets not bother with a conditional that skips both ref modifications when the ids are equal.
24205 756 uint32_t id = SH::read_stack(offset);
24206 756 script_object_ref_inc(new_id);
24207
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 738 times.
756 if (ri->stack_pos_is_object.contains(offset))
24208 18 script_object_ref_dec(id);
24209 else
24210 738 ri->stack_pos_is_object.insert(offset);
24211
24212 756 SH::write_stack(offset, new_id);
24213 756 }
24214
24215 void do_store_object(const bool v)
24216 {
24217 const int32_t stackoffset = ri->d[rSFRAME] + sarg2;
24218 const int32_t new_id = SH::get_arg(sarg1, v);
24219 script_store_object(stackoffset, new_id);
24220 }
24221
24222 1858 void script_remove_object_ref(int32_t offset)
24223 {
24224
1/2
✓ Branch 0 taken 1858 times.
✗ Branch 1 not taken.
1858 if (offset < 0 || offset >= MAX_SCRIPT_REGISTERS)
24225 {
24226 assert(false);
24227 return;
24228 }
24229
24230
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1856 times.
1858 if (!ri->stack_pos_is_object.contains(offset))
24231 2 return;
24232
24233 1856 uint32_t id = SH::read_stack(offset);
24234 1856 script_object_ref_dec(id);
24235 1856 ri->stack_pos_is_object.erase(offset);
24236 1858 }
24237
24238 void do_enqueue(const bool)
24239 {
24240 }
24241 void do_dequeue(const bool)
24242 {
24243 }
24244
24245 2013 void do_comp(bool v, const bool inv = false)
24246 {
24247 2013 bool v2 = false;
24248
1/2
✓ Branch 0 taken 2013 times.
✗ Branch 1 not taken.
2013 if(inv) zc_swap(v,v2);
24249 2013 ri->cmp_op2 = SH::get_arg(sarg2, v);
24250 2013 ri->cmp_op1 = SH::get_arg(sarg1, v2);
24251 2013 ri->cmp_strcache = nullopt;
24252 2013 }
24253
24254 void do_internal_strcmp()
24255 {
24256 int32_t arrayptr_a = get_register(sarg1)/10000;
24257 int32_t arrayptr_b = get_register(sarg2)/10000;
24258 string strA;
24259 string strB;
24260 ArrayH::getString(arrayptr_a, strA);
24261 ArrayH::getString(arrayptr_b, strB);
24262 ri->cmp_strcache = strcmp(strA.c_str(), strB.c_str());
24263 }
24264
24265 void do_internal_stricmp()
24266 {
24267 int32_t arrayptr_a = get_register(sarg1)/10000;
24268 int32_t arrayptr_b = get_register(sarg2)/10000;
24269 string strA;
24270 string strB;
24271 ArrayH::getString(arrayptr_a, strA);
24272 ArrayH::getString(arrayptr_b, strB);
24273 ri->cmp_strcache = stricmp(strA.c_str(), strB.c_str());
24274 }
24275
24276 2 void do_resize_array()
24277 {
24278 2 int32_t size = vbound(get_register(sarg2) / 10000, 0, 214748);
24279 2 dword ptrval = get_register(sarg1) / 10000;
24280 2 ArrayManager am(ptrval);
24281 2 am.resize(size);
24282 2 }
24283
24284 void do_own_array(int arrindx, ScriptType scriptType, const int32_t UID)
24285 {
24286 ArrayManager am(arrindx);
24287
24288 if(am.internal())
24289 {
24290 Z_scripterrlog_force_trace("Cannot 'OwnArray()' an internal array '%d'\n", arrindx);
24291 return;
24292 }
24293 if(arrindx >= NUM_ZSCRIPT_ARRAYS && arrindx < NUM_ZSCRIPT_ARRAYS*2)
24294 {
24295 //ignore global arrays
24296 }
24297 else if(!am.invalid())
24298 {
24299 if(arrindx > 0 && arrindx < NUM_ZSCRIPT_ARRAYS)
24300 {
24301 arrayOwner[arrindx].reown(scriptType, UID);
24302 arrayOwner[arrindx].specOwned = true;
24303 }
24304 else if(arrindx < 0) //object array
24305 Z_scripterrlog_force_trace("Cannot 'OwnArray()' an object-based array '%d'\n", arrindx);
24306 }
24307 else Z_scripterrlog_force_trace("Tried to 'OwnArray()' an invalid array '%d'\n", arrindx);
24308 }
24309 void do_destroy_array()
24310 {
24311 int arrindx = get_register(sarg1) / 10000;
24312
24313 ArrayManager am(arrindx);
24314
24315 if(am.internal())
24316 {
24317 Z_scripterrlog_force_trace("Cannot 'DestroyArray()' an internal array '%d'\n", arrindx);
24318 return;
24319 }
24320
24321 if(arrindx >= NUM_ZSCRIPT_ARRAYS && arrindx < NUM_ZSCRIPT_ARRAYS*2)
24322 {
24323 //ignore global arrays
24324 }
24325 else if(!am.invalid())
24326 {
24327 if(arrindx > 0 && arrindx < NUM_ZSCRIPT_ARRAYS)
24328 {
24329 arrayOwner[arrindx].clear();
24330
24331 if(localRAM[arrindx].Valid())
24332 localRAM[arrindx].Clear();
24333
24334 arrayOwner[arrindx].specCleared = true;
24335 }
24336 else if(arrindx < 0) //object array
24337 Z_scripterrlog_force_trace("Cannot 'DestroyArray()' an object-based array '%d'\n", arrindx);
24338 }
24339 else Z_scripterrlog_force_trace("Tried to 'DestroyArray()' an invalid array '%d'\n", arrindx);
24340 }
24341
24342 13778376 dword allocatemem(int32_t size, bool local, ScriptType type, const uint32_t UID, script_object_type object_type)
24343 {
24344 dword ptrval;
24345
24346
1/2
✓ Branch 0 taken 13778376 times.
✗ Branch 1 not taken.
13778376 if(size < 0)
24347 {
24348 Z_scripterrlog_force_trace("Array initialized to invalid size of %d\n", size);
24349 return 0;
24350 }
24351
24352
2/2
✓ Branch 0 taken 13775417 times.
✓ Branch 1 taken 2959 times.
13778376 if(local)
24353 {
24354 //localRAM[0] is used as an invalid container, so 0 can be the NULL pointer in ZScript
24355
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 446636941 times.
✓ Branch 2 taken 432861524 times.
✓ Branch 3 taken 13775417 times.
446636941 for(ptrval = 1; ptrval < NUM_ZSCRIPT_ARRAYS && localRAM[ptrval].Valid(); ptrval++) ;
24356
24357
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13775417 times.
13775417 if(ptrval >= NUM_ZSCRIPT_ARRAYS)
24358 {
24359 Z_scripterrlog_force_trace("%d local arrays already in use, no more can be allocated\n", NUM_ZSCRIPT_ARRAYS-1);
24360 ptrval = 0;
24361 DCHECK(false);
24362 }
24363 else
24364 {
24365 13775417 ZScriptArray &a = localRAM[ptrval]; //marginally faster for large arrays if we use a reference
24366
24367 13775417 a.Resize(size);
24368 13775417 a.setValid(true);
24369 13775417 a.setObjectType(object_type);
24370
24371
2/2
✓ Branch 0 taken 212722436 times.
✓ Branch 1 taken 13775417 times.
226497853 for(dword j = 0; j < (dword)size; j++)
24372 212722436 a[j] = 0; //initialize array
24373
24374 // Keep track of which object created the array so we know which to deallocate
24375 13775417 arrayOwner[ptrval].clear();
24376 13775417 arrayOwner[ptrval].reown(type, UID);
24377 }
24378 13775417 }
24379 else
24380 {
24381 //Globals are only allocated here at first play, otherwise in init_game
24382
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 51852 times.
✓ Branch 2 taken 48893 times.
✓ Branch 3 taken 2959 times.
51852 for(ptrval = 0; ptrval < game->globalRAM.size() && game->globalRAM[ptrval].Valid(); ptrval++) ;
24383
24384
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2959 times.
2959 if(ptrval >= game->globalRAM.size())
24385 {
24386 Z_scripterrlog_force_trace("Invalid pointer value of %u passed to global allocate\n", ptrval);
24387 ptrval = 0;
24388 //this shouldn't happen, unless people are putting ALLOCATEGMEM in their ZASM scripts where they shouldn't be
24389 DCHECK(false);
24390 return ptrval;
24391 }
24392
24393 2959 ZScriptArray &a = game->globalRAM[ptrval];
24394
24395 2959 a.Resize(size);
24396 2959 a.setValid(true);
24397 2959 a.setObjectType(object_type);
24398
24399
2/2
✓ Branch 0 taken 1236294 times.
✓ Branch 1 taken 2959 times.
1239253 for(dword j = 0; j < (dword)size; j++)
24400 1236294 a[j] = 0;
24401
24402 2959 ptrval += NUM_ZSCRIPT_ARRAYS; //so each pointer has a unique value
24403 }
24404
24405 13778376 return ptrval;
24406 13778376 }
24407
24408 13778376 void do_allocatemem(bool v, const bool local, ScriptType type, const uint32_t UID)
24409 {
24410 13778376 int32_t size = SH::get_arg(sarg2, v) / 10000;
24411
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 13778376 times.
✓ Branch 2 taken 13778376 times.
✗ Branch 3 not taken.
13778376 assert(sarg3 >= 0 && sarg3 <= (int)script_object_type::last);
24412 13778376 dword ptrval = allocatemem(size, local, type, UID, (script_object_type)sarg3);
24413 13778376 set_register(sarg1, ptrval * 10000);
24414 13778376 }
24415
24416 13741280 void do_deallocatemem()
24417 {
24418 13741280 const int32_t ptrval = get_register(sarg1) / 10000;
24419
24420 13741280 FFScript::deallocateArray(ptrval);
24421 13741280 }
24422
24423 ///----------------------------------------------------------------------------------------------------//
24424 //Mathematical
24425
24426 2701 void do_add(const bool v)
24427 {
24428 2701 int32_t temp = SH::get_arg(sarg2, v);
24429 2701 int32_t temp2 = get_register(sarg1);
24430
24431 2701 set_register(sarg1, temp2 + temp);
24432 2701 }
24433
24434 552 void do_sub(bool v, const bool inv = false)
24435 {
24436 552 bool v2 = false;
24437
2/2
✓ Branch 0 taken 546 times.
✓ Branch 1 taken 6 times.
552 if(inv) zc_swap(v,v2);
24438
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 546 times.
552 auto destreg = (inv ? sarg2 : sarg1);
24439 552 int32_t temp = SH::get_arg(sarg2, v);
24440 552 int32_t temp2 = SH::get_arg(sarg1, v2);
24441 552 set_register(destreg, temp2 - temp);
24442 552 }
24443
24444 564 void do_mult(const bool v)
24445 {
24446 564 int64_t temp = SH::get_arg(sarg2, v);
24447 564 int32_t temp2 = get_register(sarg1);
24448
24449 564 set_register(sarg1, int32_t((temp * temp2) / 10000));
24450 564 }
24451
24452 7 void do_div(bool v, const bool inv = false)
24453 {
24454 7 bool v2 = false;
24455
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(inv) zc_swap(v,v2);
24456
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 auto destreg = (inv ? sarg2 : sarg1);
24457 7 int64_t temp = SH::get_arg(sarg2, v);
24458 7 int64_t temp2 = SH::get_arg(sarg1, v2);
24459
24460
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if(temp == 0)
24461 {
24462 scripting_log_error_with_context("Script attempted to divide {} by zero!", temp2);
24463 set_register(destreg, int32_t(sign(temp2) * MAX_SIGNED_32));
24464 }
24465 else
24466 {
24467 7 set_register(destreg, int32_t((temp2 * 10000) / temp));
24468 }
24469 7 }
24470
24471 415 void do_mod(bool v, const bool inv = false)
24472 {
24473 415 bool v2 = false;
24474
1/2
✓ Branch 0 taken 415 times.
✗ Branch 1 not taken.
415 if(inv) zc_swap(v,v2);
24475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 415 times.
415 auto destreg = (inv ? sarg2 : sarg1);
24476 415 int32_t temp = SH::get_arg(sarg2, v);
24477 415 int32_t temp2 = SH::get_arg(sarg1, v2);
24478
24479
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 415 times.
415 if(temp == 0)
24480 {
24481 scripting_log_error_with_context("Script attempted to modulo {} by zero!", temp2);
24482 temp = 1;
24483 }
24484
24485 415 set_register(destreg, temp2 % temp);
24486 415 }
24487
24488 16033659 void do_trig(const bool v, const byte type)
24489 {
24490 16033659 double rangle = (SH::get_arg(sarg2, v) / 10000.0) * PI / 180.0;
24491
24492
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9550421 times.
✓ Branch 2 taken 6483138 times.
✓ Branch 3 taken 100 times.
16033659 switch(type)
24493 {
24494 case 0:
24495 9550421 set_register(sarg1, int32_t(zc::math::Sin(rangle) * 10000.0));
24496 9550421 break;
24497
24498 case 1:
24499 6483138 set_register(sarg1, int32_t(zc::math::Cos(rangle) * 10000.0));
24500 6483138 break;
24501
24502 case 2:
24503 100 set_register(sarg1, int32_t(zc::math::Tan(rangle) * 10000.0));
24504 100 break;
24505 }
24506 16033659 }
24507
24508 1480 void do_degtorad()
24509 {
24510 1480 double rangle = (SH::get_arg(sarg2, false) / 10000.0) * (PI / 180.0);
24511 1480 rangle += rangle < 0?-0.00005:0.00005;
24512
24513 1480 set_register(sarg1, int32_t(rangle * 10000.0));
24514 1480 }
24515
24516 138537 void do_radtodeg()
24517 {
24518 138537 double rangle = (SH::get_arg(sarg2, false) / 10000.0) * (180.0 / PI);
24519
24520 138537 set_register(sarg1, int32_t(rangle * 10000.0));
24521 138537 }
24522
24523 14918 void do_asin(const bool v)
24524 {
24525 14918 double temp = double(SH::get_arg(sarg2, v)) / 10000.0;
24526
24527
2/4
✓ Branch 0 taken 14918 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14918 times.
✗ Branch 3 not taken.
14918 if(temp >= -1 && temp <= 1)
24528 14918 set_register(sarg1, int32_t(asin(temp) * 10000.0));
24529 else
24530 {
24531 Z_scripterrlog("Script attempted to pass %ld into ArcSin!\n",temp);
24532 set_register(sarg1, -10000);
24533 }
24534 14918 }
24535
24536 void do_acos(const bool v)
24537 {
24538 double temp = double(SH::get_arg(sarg2, v)) / 10000.0;
24539
24540 if(temp >= -1 && temp <= 1)
24541 set_register(sarg1, int32_t(acos(temp) * 10000.0));
24542 else
24543 {
24544 Z_scripterrlog("Script attempted to pass %ld into ArcCos!\n",temp);
24545 set_register(sarg1, -10000);
24546 }
24547 }
24548
24549 5879938 void do_arctan()
24550 {
24551 5879938 double xpos = ri->d[rINDEX] / 10000.0;
24552 5879938 double ypos = ri->d[rINDEX2] / 10000.0;
24553
24554 5879938 set_register(sarg1, int32_t(atan2(ypos, xpos) * 10000.0));
24555 5879938 }
24556
24557 void do_abs(const bool v)
24558 {
24559 int32_t temp = SH::get_arg(sarg1, v);
24560 set_register(sarg1, abs(temp));
24561 }
24562
24563 969 void do_log10(const bool v)
24564 {
24565 969 double temp = double(SH::get_arg(sarg1, v)) / 10000.0;
24566
24567
1/2
✓ Branch 0 taken 969 times.
✗ Branch 1 not taken.
969 if(temp > 0)
24568 969 set_register(sarg1, int32_t(log10(temp) * 10000.0));
24569 else
24570 {
24571 Z_scripterrlog("Script tried to calculate log of %f\n", temp / 10000.0);
24572 set_register(sarg1, 0);
24573 }
24574 969 }
24575
24576 648 void do_naturallog(const bool v)
24577 {
24578 648 double temp = double(SH::get_arg(sarg1, v)) / 10000.0;
24579
24580
1/2
✓ Branch 0 taken 648 times.
✗ Branch 1 not taken.
648 if(temp > 0)
24581 648 set_register(sarg1, int32_t(log(temp) * 10000.0));
24582 else
24583 {
24584 Z_scripterrlog("Script tried to calculate ln of %f\n", temp / 10000.0);
24585 set_register(sarg1, 0);
24586 }
24587 648 }
24588
24589 void do_min(const bool v)
24590 {
24591 int32_t temp = SH::get_arg(sarg2, v);
24592 int32_t temp2 = get_register(sarg1);
24593 set_register(sarg1, zc_min(temp2, temp));
24594 }
24595
24596 void do_max(const bool v)
24597 {
24598 int32_t temp = SH::get_arg(sarg2, v);
24599 int32_t temp2 = get_register(sarg1);
24600
24601 set_register(sarg1, zc_max(temp2, temp));
24602 }
24603 void do_wrap_rad(const bool v)
24604 {
24605 ri->d[rEXP1] = wrap_zslong_rad(SH::get_arg(sarg1, v));
24606 }
24607 2397 void do_wrap_deg(const bool v)
24608 {
24609 2397 ri->d[rEXP1] = wrap_zslong_deg(SH::get_arg(sarg1, v));
24610 2397 }
24611
24612
24613 2912197 void do_rnd(const bool v)
24614 {
24615 2912197 int32_t temp = SH::get_arg(sarg2, v) / 10000;
24616
24617
2/2
✓ Branch 0 taken 2886432 times.
✓ Branch 1 taken 25765 times.
2912197 if(temp > 0)
24618 2886432 set_register(sarg1, (zc_oldrand() % temp) * 10000);
24619
2/2
✓ Branch 0 taken 2755 times.
✓ Branch 1 taken 23010 times.
25765 else if(temp < 0)
24620 2755 set_register(sarg1, (zc_oldrand() % (-temp)) * -10000);
24621 else
24622 23010 set_register(sarg1, 0); // Just return 0. (Do not log an error)
24623 2912197 }
24624
24625 void do_srnd(const bool v)
24626 {
24627 uint32_t seed = SH::get_arg(sarg1, v); //Do not `/10000`- allow the decimal portion to be used! -V
24628 zc_game_srand(seed);
24629 }
24630
24631 void do_srndrnd()
24632 {
24633 //Randomize the seed to the current system time, + or - the product of 2 random numbers.
24634 int32_t seed = time(0) + ((zc_rand() * int64_t(zc_rand())) * (zc_rand(1) ? 1 : -1));
24635 set_register(sarg1, seed);
24636 zc_game_srand(seed);
24637 }
24638
24639 //Returns the system Real-Time-Clock value for a specific type.
24640 15 void FFScript::getRTC(const bool v)
24641 {
24642 //int32_t type = get_register(sarg1) / 10000;
24643 //int32_t time = getTime(type);
24644 //set_register(sarg1, getTime((byte)(SH::get_arg(sarg2, v) / 10000)) * 10000);
24645 15 set_register(sarg1, getTime((get_register(sarg1) / 10000)) * 10000);
24646 15 }
24647
24648
24649 void do_factorial(const bool v)
24650 {
24651 int32_t temp;
24652
24653 if(v)
24654 return; //must factorial a register, not a value (why is this exactly? ~Joe123)
24655 else
24656 {
24657 temp = get_register(sarg1) / 10000;
24658
24659 if(temp < 2)
24660 {
24661 set_register(sarg1, temp >= 0 ? 10000 : 00000);
24662 return;
24663 }
24664 }
24665
24666 int32_t temp2 = 1;
24667
24668 for(int32_t temp3 = temp; temp > 1; temp--)
24669 temp2 *= temp3;
24670
24671 set_register(sarg1, temp2 * 10000);
24672 }
24673
24674 6556 void do_power(bool v, const bool inv = false)
24675 {
24676 6556 bool v2 = false;
24677
1/2
✓ Branch 0 taken 6556 times.
✗ Branch 1 not taken.
6556 if(inv) zc_swap(v,v2);
24678
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6556 times.
6556 auto destreg = (inv ? sarg2 : sarg1);
24679 6556 double temp = double(SH::get_arg(sarg2, v)) / 10000.0;
24680 6556 double temp2 = double(SH::get_arg(sarg1, v2)) / 10000.0;
24681
24682
3/4
✓ Branch 0 taken 1293 times.
✓ Branch 1 taken 5263 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1293 times.
6556 if(temp == 0 && temp2 == 0)
24683 {
24684 set_register(destreg, 10000);
24685 return;
24686 }
24687
24688 6556 set_register(destreg, int32_t(pow(temp2, temp) * 10000.0));
24689 6556 }
24690
24691 void do_lpower(bool v, const bool inv = false)
24692 {
24693 bool v2 = false;
24694 if(inv) zc_swap(v,v2);
24695 auto destreg = (inv ? sarg2 : sarg1);
24696 int32_t temp = SH::get_arg(sarg2, v);
24697 int32_t temp2 = SH::get_arg(sarg1, v2);
24698
24699 if(temp == 0 && temp2 == 0)
24700 {
24701 set_register(destreg, 1);
24702 return;
24703 }
24704
24705 set_register(destreg, int32_t(pow(temp2, temp)));
24706 }
24707
24708 //could use recursion or something to avoid truncation.
24709 void do_ipower(const bool v)
24710 {
24711 double sarg2val = double(SH::get_arg(sarg2, v));
24712 if ( sarg2val == 0 )
24713 {
24714 Z_scripterrlog("Division by 0 Err: InvPower() exponent divisor cannot be 0!!\n");
24715 set_register(sarg1, 1);
24716 return;
24717 }
24718 double temp = 10000.0 / sarg2val;
24719 double temp2 = double(get_register(sarg1)) / 10000.0;
24720
24721 if(temp == 0 && temp2 == 0)
24722 {
24723 set_register(sarg1, 1);
24724 return;
24725 }
24726
24727 set_register(sarg1, int32_t(pow(temp2, temp) * 10000.0));
24728 }
24729
24730 10089782 void do_sqroot(const bool v)
24731 {
24732 10089782 double temp = double(SH::get_arg(sarg2, v)) / 10000.0;
24733
24734
2/2
✓ Branch 0 taken 422 times.
✓ Branch 1 taken 10089360 times.
10089782 if(temp < 0)
24735 {
24736 422 Z_scripterrlog("Script attempted to calculate square root of %ld!\n", temp);
24737 422 set_register(sarg1, -10000);
24738 422 return;
24739 }
24740
24741 10089360 set_register(sarg1, int32_t(sqrt(temp) * 10000.0));
24742 10089782 }
24743
24744 ///----------------------------------------------------------------------------------------------------//
24745 //Bitwise
24746
24747 1 void do_and(const bool v)
24748 {
24749 1 int32_t temp = SH::get_arg(sarg2, v) / 10000;
24750 1 int32_t temp2 = get_register(sarg1) / 10000;
24751 1 set_register(sarg1, (temp2 & temp) * 10000);
24752 1 }
24753
24754 45050 void do_and32(const bool v)
24755 {
24756 45050 int32_t temp = SH::get_arg(sarg2, v);
24757 45050 int32_t temp2 = get_register(sarg1);
24758 45050 set_register(sarg1, (temp2 & temp));
24759 45050 }
24760
24761 9437045 void do_or(const bool v)
24762 {
24763 9437045 int32_t temp = SH::get_arg(sarg2, v) / 10000;
24764 9437045 int32_t temp2 = get_register(sarg1) / 10000;
24765 9437045 set_register(sarg1, (temp2 | temp) * 10000);
24766 9437045 }
24767
24768 17 void do_or32(const bool v)
24769 {
24770 17 int32_t temp = SH::get_arg(sarg2, v);
24771 17 int32_t temp2 = get_register(sarg1);
24772 17 set_register(sarg1, (temp2 | temp));
24773 17 }
24774
24775 921308 void do_xor(const bool v)
24776 {
24777 921308 int32_t temp = SH::get_arg(sarg2, v) / 10000;
24778 921308 int32_t temp2 = get_register(sarg1) / 10000;
24779 921308 set_register(sarg1, (temp2 ^ temp) * 10000);
24780 921308 }
24781
24782 void do_xor32(const bool v)
24783 {
24784 int32_t temp = SH::get_arg(sarg2, v);
24785 int32_t temp2 = get_register(sarg1);
24786 set_register(sarg1, (temp2 ^ temp));
24787 }
24788
24789 void do_nand(const bool v)
24790 {
24791 int32_t temp = SH::get_arg(sarg2, v) / 10000;
24792 int32_t temp2 = get_register(sarg1) / 10000;
24793 set_register(sarg1, (~(temp2 & temp)) * 10000);
24794 }
24795
24796 void do_nor(const bool v)
24797 {
24798 int32_t temp = SH::get_arg(sarg2, v) / 10000;
24799 int32_t temp2 = get_register(sarg1) / 10000;
24800 set_register(sarg1, (~(temp2 | temp)) * 10000);
24801 }
24802
24803 void do_xnor(const bool v)
24804 {
24805 int32_t temp = SH::get_arg(sarg2, v) / 10000;
24806 int32_t temp2 = get_register(sarg1) / 10000;
24807 set_register(sarg1, (~(temp2 ^ temp)) * 10000);
24808 }
24809
24810 void do_not(const bool v)
24811 {
24812 int32_t temp = SH::get_arg(sarg2, v);
24813 set_register(sarg1, !temp);
24814 }
24815
24816 3709786 void do_bitwisenot(const bool v)
24817 {
24818 3709786 int32_t temp = SH::get_arg(sarg1, v) / 10000;
24819 3709786 set_register(sarg1, (~temp) * 10000);
24820 3709786 }
24821
24822 void do_bitwisenot32(const bool v)
24823 {
24824 int32_t temp = SH::get_arg(sarg1, v);
24825 set_register(sarg1, (~temp));
24826 }
24827
24828 76716802 void do_lshift(const bool v)
24829 {
24830 76716802 int32_t temp = SH::get_arg(sarg2, v) / 10000;
24831 76716802 int32_t temp2 = get_register(sarg1) / 10000;
24832 76716802 set_register(sarg1, (temp2 << temp) * 10000);
24833 76716802 }
24834
24835 22 void do_lshift32(const bool v)
24836 {
24837 22 int32_t temp = SH::get_arg(sarg2, v) / 10000;
24838 22 int32_t temp2 = get_register(sarg1);
24839 22 set_register(sarg1, (temp2 << temp));
24840 22 }
24841
24842 31394534 void do_rshift(const bool v)
24843 {
24844 31394534 int32_t temp = SH::get_arg(sarg2, v) / 10000;
24845 31394534 int32_t temp2 = get_register(sarg1) / 10000;
24846 31394534 set_register(sarg1, (temp2 >> temp) * 10000);
24847 31394534 }
24848
24849 34296 void do_rshift32(const bool v)
24850 {
24851 34296 int32_t temp = SH::get_arg(sarg2, v) / 10000;
24852 34296 int32_t temp2 = get_register(sarg1);
24853 34296 set_register(sarg1, (temp2 >> temp));
24854 34296 }
24855
24856 ///----------------------------------------------------------------------------------------------------//
24857 //Casting
24858
24859 17 void do_boolcast(const bool isFloat)
24860 {
24861
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 12 times.
17 set_register(sarg1, (get_register(sarg1) ? (isFloat ? 1 : 10000) : 0));
24862 17 }
24863
24864 ///----------------------------------------------------------------------------------------------------//
24865 //Text ptr functions
24866 6352 void do_fontheight()
24867 {
24868 6352 int32_t font = get_register(sarg1)/10000;
24869 6352 ri->d[rEXP1] = text_height(get_zc_font(font))*10000;
24870 6352 }
24871
24872 17821 void do_strwidth()
24873 {
24874 17821 int32_t strptr = get_register(sarg1)/10000;
24875 17821 int32_t font = get_register(sarg2)/10000;
24876 17821 string the_string;
24877
1/2
✓ Branch 0 taken 17821 times.
✗ Branch 1 not taken.
17821 ArrayH::getString(strptr, the_string, 512);
24878
2/4
✓ Branch 0 taken 17821 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17821 times.
✗ Branch 3 not taken.
17821 ri->d[rEXP1] = text_length(get_zc_font(font), the_string.c_str())*10000;
24879 17821 }
24880
24881 37547 void do_charwidth()
24882 {
24883 37547 char chr = get_register(sarg1)/10000;
24884 37547 int32_t font = get_register(sarg2)/10000;
24885 37547 char *cstr = new char[2];
24886 37547 cstr[0] = chr;
24887 37547 cstr[1] = '\0';
24888 37547 ri->d[rEXP1] = text_length(get_zc_font(font), cstr)*10000;
24889
1/2
✓ Branch 0 taken 37547 times.
✗ Branch 1 not taken.
37547 delete[] cstr;
24890 37547 }
24891
24892 int32_t do_msgwidth(int32_t ID)
24893 {
24894 if(BC::checkMessage(ID) != SH::_NoError)
24895 {
24896 return -1;
24897 }
24898
24899 int32_t v = text_length(get_zc_font(MsgStrings[ID].font),
24900 MsgStrings[ID].s.substr(0,MsgStrings[ID].s.find_last_not_of(' ')+1).c_str());
24901 return v;
24902 }
24903
24904 int32_t do_msgheight(int32_t ID)
24905 {
24906 if(BC::checkMessage(ID) != SH::_NoError)
24907 {
24908 return -1;
24909 }
24910 return text_height(get_zc_font(MsgStrings[ID].font));
24911 }
24912
24913 ///----------------------------------------------------------------------------------------------------//
24914 //Gameplay functions
24915
24916 107 void do_warp(bool v)
24917 {
24918 107 int32_t dmapid = SH::get_arg(sarg1, v) / 10000;
24919 107 int32_t screen = SH::get_arg(sarg2, v) / 10000;
24920
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107 times.
107 if ( ((unsigned)dmapid) >= MAXDMAPS )
24921 {
24922 Z_scripterrlog("Invalid DMap ID (%d) passed to Warp(). Aborting.\n", dmapid);
24923 return;
24924 }
24925
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107 times.
107 if ( ((unsigned)screen) >= MAPSCRS )
24926 {
24927 Z_scripterrlog("Invalid Screen Index (%d) passed to Warp(). Aborting.\n", screen);
24928 return;
24929 }
24930
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107 times.
107 if ( map_screen_index(DMaps[dmapid].map, screen + DMaps[dmapid].xoff) >= (int32_t)TheMaps.size() )
24931 {
24932 Z_scripterrlog("Invalid destination passed to Warp(). Aborting.\n");
24933 return;
24934 }
24935 107 hero_scr->sidewarpdmap[0] = dmapid;
24936 107 hero_scr->sidewarpscr[0] = screen;
24937 107 hero_scr->sidewarptype[0] = wtIWARP;
24938
1/2
✓ Branch 0 taken 107 times.
✗ Branch 1 not taken.
107 if(!get_qr(qr_OLD_HERO_WARP_RETSQUARE))
24939 {
24940 hero_scr->warpreturnc &= ~(3 << 8);
24941 set_bit(&hero_scr->sidewarpoverlayflags,0,0);
24942 }
24943 107 Hero.ffwarp = true;
24944 107 }
24945
24946 127 void do_pitwarp(bool v)
24947 {
24948 127 int32_t dmapid = SH::get_arg(sarg1, v) / 10000;
24949 127 int32_t screen = SH::get_arg(sarg2, v) / 10000;
24950
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127 times.
127 if ( ((unsigned)dmapid) >= MAXDMAPS )
24951 {
24952 Z_scripterrlog("Invalid DMap ID (%d) passed to PitWarp(). Aborting.\n", dmapid);
24953 return;
24954 }
24955
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127 times.
127 if ( ((unsigned)screen) >= MAPSCRS )
24956 {
24957 Z_scripterrlog("Invalid Screen Index (%d) passed to PitWarp(). Aborting.\n", screen);
24958 return;
24959 }
24960 //Extra sanity guard.
24961
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127 times.
127 if ( map_screen_index(DMaps[dmapid].map, screen + DMaps[dmapid].xoff) >= (int32_t)TheMaps.size() )
24962 {
24963 Z_scripterrlog("Invalid destination passed to Warp(). Aborting.\n");
24964 return;
24965 }
24966 127 hero_scr->sidewarpdmap[0] = dmapid;
24967 127 hero_scr->sidewarpscr[0] = screen;
24968 127 hero_scr->sidewarptype[0] = wtIWARP;
24969
1/2
✓ Branch 0 taken 127 times.
✗ Branch 1 not taken.
127 if(!get_qr(qr_OLD_HERO_WARP_RETSQUARE))
24970 {
24971 hero_scr->warpreturnc &= ~(3 << 8);
24972 set_bit(&hero_scr->sidewarpoverlayflags,0,0);
24973 }
24974 127 Hero.ffwarp = true;
24975 127 Hero.ffpit = true;
24976 127 }
24977
24978
24979
24980 void do_showsavescreen()
24981 {
24982 bool didsaved = save_game(false, 0);
24983 set_register(sarg1, didsaved ? 10000 : 0);
24984 }
24985
24986 11096 void do_selectweapon(bool v, int32_t btn)
24987 {
24988
2/4
✓ Branch 0 taken 5436 times.
✓ Branch 1 taken 5660 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11096 switch(btn)
24989 {
24990 case 1:
24991
1/2
✓ Branch 0 taken 5660 times.
✗ Branch 1 not taken.
5660 if(!get_qr(qr_SELECTAWPN))
24992 return;
24993 5660 break;
24994 case 2:
24995 if(!get_qr(qr_SET_XBUTTON_ITEMS))
24996 return;
24997 break;
24998 case 3:
24999 if(!get_qr(qr_SET_YBUTTON_ITEMS))
25000 return;
25001 break;
25002 }
25003
25004 11096 byte dir=(byte)(SH::get_arg(sarg1, v)/10000);
25005
25006 // Selection directions don't match the normal ones...
25007
2/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 80 times.
✓ Branch 4 taken 11016 times.
11096 switch(dir)
25008 {
25009 case 0:
25010 dir=SEL_UP;
25011 break;
25012
25013 case 1:
25014 dir=SEL_DOWN;
25015 break;
25016
25017 case 2:
25018 80 dir=SEL_LEFT;
25019 80 break;
25020
25021 case 3:
25022 11016 dir=SEL_RIGHT;
25023 11016 break;
25024
25025 default:
25026 return;
25027 }
25028
25029
2/5
✗ Branch 0 not taken.
✓ Branch 1 taken 5436 times.
✓ Branch 2 taken 5660 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
11096 switch(btn)
25030 {
25031 case 0:
25032 5436 selectNextBWpn(dir);
25033 5436 break;
25034 case 1:
25035 5660 selectNextAWpn(dir);
25036 5660 break;
25037 case 2:
25038 selectNextXWpn(dir);
25039 break;
25040 case 3:
25041 selectNextYWpn(dir);
25042 break;
25043 }
25044 11096 }
25045
25046 ///----------------------------------------------------------------------------------------------------//
25047 //Screen Information
25048
25049 21032557 void do_issolid()
25050 {
25051 21032557 int32_t x = int32_t(ri->d[rINDEX] / 10000);
25052 21032557 int32_t y = int32_t(ri->d[rINDEX2] / 10000);
25053
25054 21032557 set_register(sarg1, (_walkflag(x, y, 1) ? 10000 : 0));
25055 21032557 }
25056
25057 void do_mapdataissolid()
25058 {
25059 auto result = decode_mapdata_ref(ri->mapsref);
25060 if (!result.scr)
25061 {
25062 scripting_log_error_with_context("mapdata pointer is either invalid or uninitialised");
25063 set_register(sarg1,10000);
25064 }
25065 else
25066 {
25067 int32_t x = int32_t(ri->d[rINDEX] / 10000);
25068 int32_t y = int32_t(ri->d[rINDEX2] / 10000);
25069
25070 if (result.type == mapdata_type::CanonicalScreen)
25071 {
25072 set_register(sarg1, (_walkflag(x, y, 1, result.scr) ? 10000 : 0));
25073 return;
25074 }
25075
25076 if (result.type == mapdata_type::TemporaryCurrentRegion && result.layer == 0)
25077 {
25078 set_register(sarg1, (_walkflag(x, y, 1)) ? 10000 : 0);
25079 }
25080 else if (result.type == mapdata_type::TemporaryScrollingRegion && result.layer == 0)
25081 {
25082 mapscr* s0 = GetScrollingMapscr(0, x, y);
25083 mapscr* s1 = GetScrollingMapscr(1, x, y);
25084 mapscr* s2 = GetScrollingMapscr(2, x, y);
25085 if (!s1->valid) s1 = s0;
25086 if (!s2->valid) s2 = s0;
25087 bool result = _walkflag_new(s0, s1, s2, x, y, 0_zf, true);
25088 set_register(sarg1, result ? 10000 : 0);
25089 }
25090 else
25091 {
25092 set_register(sarg1, (_walkflag(x, y, 1, result.scr) ? 10000 : 0));
25093 }
25094 }
25095 }
25096
25097 void do_mapdataissolid_layer()
25098 {
25099 auto result = decode_mapdata_ref(ri->mapsref);
25100 if (!result.scr)
25101 {
25102 scripting_log_error_with_context("mapdata pointer is either invalid or uninitialised");
25103 set_register(sarg1,10000);
25104 }
25105 else
25106 {
25107 int32_t x = int32_t(ri->d[rINDEX] / 10000);
25108 int32_t y = int32_t(ri->d[rINDEX2] / 10000);
25109 int32_t layer = int32_t(ri->d[rEXP1] / 10000);
25110 if(BC::checkBounds(layer, 0, 6) != SH::_NoError)
25111 {
25112 set_register(sarg1,10000);
25113 }
25114 else
25115 {
25116 if (result.type == mapdata_type::TemporaryCurrentRegion && result.layer == 0)
25117 {
25118 set_register(sarg1, (_walkflag_layer(x, y, 1, result.scr)) ? 10000 : 0);
25119 }
25120 else if (result.type == mapdata_type::TemporaryScrollingRegion && result.layer == 0)
25121 {
25122 set_register(sarg1, (_walkflag_layer_scrolling(x, y, 1, result.scr)) ? 10000 : 0);
25123 }
25124 else
25125 {
25126 mapscr* m = result.scr;
25127
25128 if(layer > 0)
25129 {
25130 if(m->layermap[layer] == 0)
25131 {
25132 set_register(sarg1,10000);
25133 return;
25134 }
25135
25136 m = &TheMaps[(m->layermap[layer]*MAPSCRS + m->layerscreen[layer])];
25137 }
25138
25139 set_register(sarg1, (_walkflag_layer(x, y, 1, m) ? 10000 : 0));
25140 }
25141 }
25142 }
25143 }
25144
25145 void do_issolid_layer()
25146 {
25147 int32_t x = int32_t(ri->d[rINDEX] / 10000);
25148 int32_t y = int32_t(ri->d[rINDEX2] / 10000);
25149 int32_t layer = int32_t(ri->d[rEXP1] / 10000);
25150 if(BC::checkBounds(layer, 0, 6) != SH::_NoError)
25151 {
25152 set_register(sarg1,10000);
25153 }
25154 else
25155 {
25156 set_register(sarg1, (_walkflag_layer(x, y, layer - 1, 1)) ? 10000 : 0);
25157 }
25158 }
25159
25160 257 void do_setsidewarp()
25161 {
25162 257 int32_t warp = SH::read_stack(ri->sp + 3) / 10000;
25163 257 int32_t scrn = SH::read_stack(ri->sp + 2) / 10000;
25164 257 int32_t dmap = SH::read_stack(ri->sp + 1) / 10000;
25165 257 int32_t type = SH::read_stack(ri->sp + 0) / 10000;
25166
25167 257 current_zasm_extra_context = "warp";
25168
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 257 times.
257 if (BC::checkBounds(warp, -1, 3) != SH::_NoError)
25169 return;
25170
25171 257 current_zasm_extra_context = "screen";
25172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 257 times.
257 if (BC::checkBounds(scrn, -1, 0x87) != SH::_NoError)
25173 return;
25174
25175 257 current_zasm_extra_context = "dmap";
25176
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 257 times.
257 if (BC::checkBounds(dmap, -1, MAXDMAPS - 1) != SH::_NoError)
25177 return;
25178
25179 257 current_zasm_extra_context = "type";
25180
1/2
✓ Branch 0 taken 257 times.
✗ Branch 1 not taken.
257 if (BC::checkBounds(type, -1, wtMAX - 1) != SH::_NoError)
25181 return;
25182
25183 257 current_zasm_extra_context = "";
25184
25185 257 mapscr* scr = get_scr(ri->screenref);
25186
25187
1/2
✓ Branch 0 taken 257 times.
✗ Branch 1 not taken.
257 if(scrn > -1)
25188 257 scr->sidewarpscr[warp] = scrn;
25189
25190
1/2
✓ Branch 0 taken 257 times.
✗ Branch 1 not taken.
257 if(dmap > -1)
25191 257 scr->sidewarpdmap[warp] = dmap;
25192
25193
1/2
✓ Branch 0 taken 257 times.
✗ Branch 1 not taken.
257 if(type > -1)
25194 257 scr->sidewarptype[warp] = type;
25195 257 }
25196
25197 5 void do_settilewarp()
25198 {
25199 5 int32_t warp = SH::read_stack(ri->sp + 3) / 10000;
25200 5 int32_t scrn = SH::read_stack(ri->sp + 2) / 10000;
25201 5 int32_t dmap = SH::read_stack(ri->sp + 1) / 10000;
25202 5 int32_t type = SH::read_stack(ri->sp + 0) / 10000;
25203
25204 5 current_zasm_extra_context = "warp";
25205
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (BC::checkBounds(warp, -1, 3) != SH::_NoError)
25206 return;
25207
25208 5 current_zasm_extra_context = "screen";
25209
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (BC::checkBounds(scrn, -1, 0x87) != SH::_NoError)
25210 return;
25211
25212 5 current_zasm_extra_context = "dmap";
25213
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (BC::checkBounds(dmap, -1, MAXDMAPS - 1) != SH::_NoError)
25214 return;
25215
25216 5 current_zasm_extra_context = "type";
25217
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (BC::checkBounds(type, -1, wtMAX - 1) != SH::_NoError)
25218 return;
25219
25220 5 current_zasm_extra_context = "";
25221
25222 5 mapscr* scr = get_scr(ri->screenref);
25223
25224
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(scrn > -1)
25225 5 scr->tilewarpscr[warp] = scrn;
25226
25227
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(dmap > -1)
25228 5 scr->tilewarpdmap[warp] = dmap;
25229
25230
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(type > -1)
25231 5 scr->tilewarptype[warp] = type;
25232 5 }
25233
25234 354947 void do_getsidewarpdmap(const bool v)
25235 {
25236 354947 int32_t warp = SH::get_arg(sarg1, v) / 10000;
25237
25238
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 354947 times.
354947 if(BC::checkBounds(warp, -1, 3) != SH::_NoError)
25239 {
25240 set_register(sarg1, -10000);
25241 return;
25242 }
25243
25244 354947 set_register(sarg1, get_scr(ri->screenref)->sidewarpdmap[warp]*10000);
25245 354947 }
25246
25247 3 void do_getsidewarpscr(const bool v)
25248 {
25249 3 int32_t warp = SH::get_arg(sarg1, v) / 10000;
25250
25251
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(BC::checkBounds(warp, -1, 3) != SH::_NoError)
25252 {
25253 set_register(sarg1, -10000);
25254 return;
25255 }
25256
25257 3 set_register(sarg1, get_scr(ri->screenref)->sidewarpscr[warp]*10000);
25258 3 }
25259
25260 void do_getsidewarptype(const bool v)
25261 {
25262 int32_t warp = SH::get_arg(sarg1, v) / 10000;
25263
25264 if(BC::checkBounds(warp, -1, 3) != SH::_NoError)
25265 {
25266 set_register(sarg1, -10000);
25267 return;
25268 }
25269
25270 set_register(sarg1, get_scr(ri->screenref)->sidewarptype[warp]*10000);
25271 }
25272
25273 354994 void do_gettilewarpdmap(const bool v)
25274 {
25275 354994 int32_t warp = SH::get_arg(sarg1, v) / 10000;
25276
25277
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 354994 times.
354994 if(BC::checkBounds(warp, -1, 3) != SH::_NoError)
25278 {
25279 set_register(sarg1, -10000);
25280 return;
25281 }
25282
25283 354994 set_register(sarg1, get_scr(ri->screenref)->tilewarpdmap[warp]*10000);
25284 354994 }
25285
25286 50 void do_gettilewarpscr(const bool v)
25287 {
25288 50 int32_t warp = SH::get_arg(sarg1, v) / 10000;
25289
25290
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if(BC::checkBounds(warp, -1, 3) != SH::_NoError)
25291 {
25292 set_register(sarg1, -10000);
25293 return;
25294 }
25295
25296 50 set_register(sarg1, get_scr(ri->screenref)->tilewarpscr[warp]*10000);
25297 50 }
25298
25299 3 void do_gettilewarptype(const bool v)
25300 {
25301 3 int32_t warp = SH::get_arg(sarg1, v) / 10000;
25302
25303
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(BC::checkBounds(warp, -1, 3) != SH::_NoError)
25304 {
25305 set_register(sarg1, -10000);
25306 return;
25307 }
25308
25309 3 set_register(sarg1, get_scr(ri->screenref)->tilewarptype[warp]*10000);
25310 3 }
25311
25312 13670631 void do_layerscreen()
25313 {
25314 13670631 int32_t layer = (get_register(sarg2) / 10000) - 1;
25315
25316
3/4
✓ Branch 0 taken 13670631 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11796293 times.
✓ Branch 3 taken 1874338 times.
13670631 if(BC::checkBounds(layer, 0, 5) != SH::_NoError || get_scr(ri->screenref)->layermap[layer] == 0)
25317 1874338 set_register(sarg1, -10000);
25318 else
25319 11796293 set_register(sarg1, get_scr(ri->screenref)->layerscreen[layer] * 10000);
25320 13670631 }
25321
25322 18282859 void do_layermap()
25323 {
25324 18282859 int32_t layer = (get_register(sarg2) / 10000) - 1;
25325
25326
3/4
✓ Branch 0 taken 18282859 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15796322 times.
✓ Branch 3 taken 2486537 times.
18282859 if(BC::checkBounds(layer, 0, 5) != SH::_NoError || get_scr(ri->screenref)->layermap[layer] == 0)
25327 2486537 set_register(sarg1, -10000);
25328 else
25329 15796322 set_register(sarg1, get_scr(ri->screenref)->layermap[layer] * 10000);
25330 18282859 }
25331
25332
25333
25334 475 void do_triggersecrets(int screen)
25335 {
25336
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 475 times.
475 if (!is_in_current_region(screen))
25337 {
25338 scripting_log_error_with_context("Must be given a screen in the current region. got: {}", screen);
25339 return;
25340 }
25341
25342 475 trigger_secrets_for_screen(TriggerSource::Script, screen, false);
25343 475 }
25344
25345 void FFScript::do_graphics_getpixel()
25346 {
25347 int32_t yoffset = 0;
25348 const bool brokenOffset= ( (get_er(er_BITMAPOFFSET)!=0) || (get_qr(qr_BITMAPOFFSETFIX)!=0) );
25349 int32_t ref = (ri->d[rEXP1]);
25350
25351 BITMAP *bitty = FFCore.GetScriptBitmap(ref);
25352 int32_t xpos = ri->d[rINDEX2] / 10000;
25353
25354 if(!brokenOffset && (ref-10) == -1 )
25355 {
25356 yoffset = 56; //should this be -56?
25357 }
25358 else
25359 {
25360 yoffset = 0;
25361 }
25362
25363 int32_t ypos = (ri->d[rINDEX] / 10000)+yoffset;
25364 if(!bitty)
25365 {
25366 bitty = scrollbuf;
25367 }
25368
25369 int32_t ret = getpixel(bitty, xpos, ypos); //This is a palette index value.
25370
25371 if(!get_qr(qr_BROKEN_GETPIXEL_VALUE))
25372 ret *= 10000;
25373 set_register(sarg1, ret);
25374 }
25375
25376
25377
25378
25379 ///----------------------------------------------------------------------------------------------------//
25380 //Pointer handling
25381
25382 573 bool is_valid_array(int32_t ptr)
25383 {
25384
2/2
✓ Branch 0 taken 567 times.
✓ Branch 1 taken 6 times.
573 if(!ptr) return false;
25385
25386
2/2
✓ Branch 0 taken 565 times.
✓ Branch 1 taken 2 times.
567 if(ptr < 0) //An object array?
25387 {
25388 2 int32_t objptr = -ptr;
25389 2 auto it = objectRAM.find(objptr);
25390
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(it == objectRAM.end())
25391 return false;
25392 2 return true;
25393 }
25394
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 565 times.
565 else if(ptr >= NUM_ZSCRIPT_ARRAYS) //check global
25395 {
25396 dword gptr = ptr - NUM_ZSCRIPT_ARRAYS;
25397
25398 if(gptr > game->globalRAM.size())
25399 return false;
25400 else return game->globalRAM[gptr].Valid();
25401 }
25402 else
25403 {
25404 565 return localRAM[ptr].Valid();
25405 }
25406 573 }
25407
25408 573 void do_isvalidarray()
25409 {
25410 573 int32_t ptr = get_register(sarg1)/10000;
25411
25412 573 set_register(sarg1,is_valid_array(ptr) ? 10000 : 0);
25413 573 }
25414
25415 31487 void do_isvaliditem()
25416 {
25417 31487 int32_t IID = get_register(sarg1);
25418 //int32_t ct = items.Count();
25419
25420 //for ( int32_t j = items.Count()-1; j >= 0; --j )
25421
2/2
✓ Branch 0 taken 55605 times.
✓ Branch 1 taken 213 times.
55818 for(int32_t j = 0; j < items.Count(); j++)
25422 //for(int32_t j = 0; j < ct; j++)
25423
2/2
✓ Branch 0 taken 31274 times.
✓ Branch 1 taken 24331 times.
55605 if(items.spr(j)->getUID() == IID)
25424 {
25425 31274 set_register(sarg1, 10000);
25426 31274 return;
25427 }
25428
25429 213 set_register(sarg1, 0);
25430 31487 }
25431
25432 11754119 void do_isvalidnpc()
25433 {
25434 11754119 int32_t UID = get_register(sarg1);
25435 //for ( int32_t j = guys.Count()-1; j >= 0; --j )
25436 //int32_t ct = guys.Count();
25437
25438
2/2
✓ Branch 0 taken 34202049 times.
✓ Branch 1 taken 112140 times.
34314189 for(int32_t j = 0; j < guys.Count(); j++)
25439 //for(int32_t j = 0; j < ct; j++)
25440
2/2
✓ Branch 0 taken 11641979 times.
✓ Branch 1 taken 22560070 times.
34202049 if(guys.spr(j)->getUID() == UID)
25441 {
25442 11641979 set_register(sarg1, 10000);
25443 11641979 return;
25444 }
25445
25446 112140 set_register(sarg1, 0);
25447 11754119 }
25448
25449 1205956 void do_isvalidlwpn()
25450 {
25451 1205956 int32_t WID = get_register(sarg1);
25452 //int32_t ct = Lwpns.Count();
25453
25454 //for ( int32_t j = Lwpns.Count()-1; j >= 0; --j )
25455
2/2
✓ Branch 0 taken 3080447 times.
✓ Branch 1 taken 590865 times.
3671312 for(int32_t j = 0; j < Lwpns.Count(); j++)
25456 //for(int32_t j = 0; j < ct; j++)
25457
2/2
✓ Branch 0 taken 2465356 times.
✓ Branch 1 taken 615091 times.
3080447 if(Lwpns.spr(j)->getUID() == WID)
25458 {
25459 615091 set_register(sarg1, 10000);
25460 615091 return;
25461 }
25462
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 590865 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
590865 if(Hero.lift_wpn && Hero.lift_wpn->getUID() == WID)
25463 {
25464 set_register(sarg1, 10000);
25465 return;
25466 }
25467 590865 set_register(sarg1, 0);
25468 1205956 }
25469
25470 160009 void do_isvalidewpn()
25471 {
25472 160009 int32_t WID = get_register(sarg1);
25473
25474
2/2
✓ Branch 0 taken 961177 times.
✓ Branch 1 taken 23757 times.
984934 for(int32_t j = 0; j < Ewpns.Count(); j++)
25475
2/2
✓ Branch 0 taken 824925 times.
✓ Branch 1 taken 136252 times.
961177 if(Ewpns.spr(j)->getUID() == WID)
25476 {
25477 136252 set_register(sarg1, 10000);
25478 136252 return;
25479 }
25480 // unsure how an ewpn would be lifted, but, checking just to be safe
25481
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 23757 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
23757 if(Hero.lift_wpn && Hero.lift_wpn->getUID() == WID)
25482 {
25483 set_register(sarg1, 10000);
25484 return;
25485 }
25486 23757 set_register(sarg1, 0);
25487 160009 }
25488
25489 void do_lwpnmakeangular()
25490 {
25491 if(LwpnH::loadWeapon(ri->lwpn) == SH::_NoError)
25492 {
25493 if (!LwpnH::getWeapon()->angular)
25494 {
25495 double vx;
25496 double vy;
25497 switch(NORMAL_DIR(LwpnH::getWeapon()->dir))
25498 {
25499 case l_up:
25500 case l_down:
25501 case left:
25502 vx = -1.0*((weapon*)s)->step;
25503 break;
25504 case r_down:
25505 case r_up:
25506 case right:
25507 vx = ((weapon*)s)->step;
25508 break;
25509
25510 default:
25511 vx = 0;
25512 break;
25513 }
25514 switch(NORMAL_DIR(LwpnH::getWeapon()->dir))
25515 {
25516 case l_up:
25517 case r_up:
25518 case up:
25519 vy = -1.0*((weapon*)s)->step;
25520 break;
25521 case l_down:
25522 case r_down:
25523 case down:
25524 vy = ((weapon*)s)->step;
25525 break;
25526
25527 default:
25528 vy = 0;
25529 break;
25530 }
25531 LwpnH::getWeapon()->angular = true;
25532 LwpnH::getWeapon()->angle=atan2(vy, vx);
25533 LwpnH::getWeapon()->step=FFCore.Distance(0, 0, vx, vy)/10000.0;
25534 LwpnH::getWeapon()->doAutoRotate();
25535 }
25536 }
25537 }
25538
25539 void do_lwpnmakedirectional()
25540 {
25541 if(LwpnH::loadWeapon(ri->lwpn) == SH::_NoError)
25542 {
25543 if (LwpnH::getWeapon()->angular)
25544 {
25545 LwpnH::getWeapon()->dir = NORMAL_DIR(AngleToDir(WrapAngle(LwpnH::getWeapon()->angle)));
25546 LwpnH::getWeapon()->angular = false;
25547 LwpnH::getWeapon()->doAutoRotate(true);
25548 }
25549 }
25550 }
25551
25552 void do_ewpnmakeangular()
25553 {
25554 if(EwpnH::loadWeapon(ri->ewpn) == SH::_NoError)
25555 {
25556 if (!EwpnH::getWeapon()->angular)
25557 {
25558 double vx;
25559 double vy;
25560 switch(NORMAL_DIR(EwpnH::getWeapon()->dir))
25561 {
25562 case l_up:
25563 case l_down:
25564 case left:
25565 vx = -1.0*((weapon*)s)->step;
25566 break;
25567 case r_down:
25568 case r_up:
25569 case right:
25570 vx = ((weapon*)s)->step;
25571 break;
25572
25573 default:
25574 vx = 0;
25575 break;
25576 }
25577 switch(NORMAL_DIR(EwpnH::getWeapon()->dir))
25578 {
25579 case l_up:
25580 case r_up:
25581 case up:
25582 vy = -1.0*((weapon*)s)->step;
25583 break;
25584 case l_down:
25585 case r_down:
25586 case down:
25587 vy = ((weapon*)s)->step;
25588 break;
25589
25590 default:
25591 vy = 0;
25592 break;
25593 }
25594 EwpnH::getWeapon()->angular = true;
25595 EwpnH::getWeapon()->angle=atan2(vy, vx);
25596 EwpnH::getWeapon()->step=FFCore.Distance(0, 0, vx, vy)/10000.0;
25597 EwpnH::getWeapon()->doAutoRotate();
25598 }
25599 }
25600 }
25601
25602 void do_ewpnmakedirectional()
25603 {
25604 if(EwpnH::loadWeapon(ri->lwpn) == SH::_NoError)
25605 {
25606 if (EwpnH::getWeapon()->angular)
25607 {
25608 EwpnH::getWeapon()->dir = NORMAL_DIR(AngleToDir(WrapAngle(EwpnH::getWeapon()->angle)));
25609 EwpnH::getWeapon()->angular = false;
25610 EwpnH::getWeapon()->doAutoRotate(true);
25611 }
25612 }
25613 }
25614
25615 19653 void do_lwpnusesprite(const bool v)
25616 {
25617 19653 int32_t ID = SH::get_arg(sarg1, v) / 10000;
25618
25619
1/2
✓ Branch 0 taken 19653 times.
✗ Branch 1 not taken.
19653 if(BC::checkWeaponMiscSprite(ID) != SH::_NoError)
25620 return;
25621
25622
1/2
✓ Branch 0 taken 19653 times.
✗ Branch 1 not taken.
19653 if(LwpnH::loadWeapon(ri->lwpn) == SH::_NoError)
25623 19653 LwpnH::getWeapon()->LOADGFX(ID);
25624 19653 }
25625
25626 208946 void do_ewpnusesprite(const bool v)
25627 {
25628 208946 int32_t ID = SH::get_arg(sarg1, v) / 10000;
25629
25630
1/2
✓ Branch 0 taken 208946 times.
✗ Branch 1 not taken.
208946 if(BC::checkWeaponMiscSprite(ID) != SH::_NoError)
25631 return;
25632
25633
1/2
✓ Branch 0 taken 208946 times.
✗ Branch 1 not taken.
208946 if(EwpnH::loadWeapon(ri->ewpn) == SH::_NoError)
25634 208946 EwpnH::getWeapon()->LOADGFX(ID);
25635 208946 }
25636
25637 void do_portalusesprite()
25638 {
25639 int32_t ID = get_register(sarg1) / 10000;
25640
25641 if(BC::checkWeaponMiscSprite(ID) != SH::_NoError)
25642 return;
25643
25644 if(portal* p = checkPortal(ri->portalref))
25645 p->LOADGFX(ID);
25646 }
25647
25648 void do_clearsprites(const bool v)
25649 {
25650 int32_t spritelist = SH::get_arg(sarg1, v) / 10000;
25651
25652 if(BC::checkBounds(spritelist, 0, 5) != SH::_NoError)
25653 return;
25654
25655 switch(spritelist)
25656 {
25657 case 0:
25658 guys.clear();
25659 break;
25660
25661 case 1:
25662 items.clear();
25663 break;
25664
25665 case 2:
25666 Ewpns.clear();
25667 break;
25668
25669 case 3:
25670 Lwpns.clear();
25671 Hero.reset_hookshot();
25672 break;
25673
25674 case 4:
25675 decorations.clear();
25676 break;
25677
25678 case 5:
25679 particles.clear();
25680 break;
25681 }
25682 }
25683
25684 1452537 void do_loadlweapon(const bool v)
25685 {
25686 1452537 int32_t index = SH::get_arg(sarg1, v) / 10000;
25687
25688
2/2
✓ Branch 0 taken 16630 times.
✓ Branch 1 taken 1435907 times.
1452537 if(BC::checkLWeaponIndex(index) != SH::_NoError)
25689 16630 ri->lwpn = 0; //MAX_DWORD; //Now NULL
25690 else
25691 {
25692 1435907 ri->lwpn = Lwpns.spr(index)->getUID();
25693 // This is too trivial to log. -L
25694 }
25695 1452537 }
25696
25697 4712414 void do_loadeweapon(const bool v)
25698 {
25699 4712414 int32_t index = SH::get_arg(sarg1, v) / 10000;
25700
25701
2/2
✓ Branch 0 taken 68863 times.
✓ Branch 1 taken 4643551 times.
4712414 if(BC::checkEWeaponIndex(index) != SH::_NoError)
25702 68863 ri->ewpn = 0; //MAX_DWORD; //Now NULL
25703 else
25704 {
25705 4643551 ri->ewpn = Ewpns.spr(index)->getUID();
25706 }
25707 4712414 }
25708
25709 585769 void do_loaditem(const bool v)
25710 {
25711 585769 int32_t index = SH::get_arg(sarg1, v) / 10000;
25712
25713
2/2
✓ Branch 0 taken 298944 times.
✓ Branch 1 taken 286825 times.
585769 if(BC::checkItemIndex(index) != SH::_NoError)
25714 298944 ri->itemref = 0; //MAX_DWORD; //Now NULL
25715 else
25716 {
25717 286825 ri->itemref = items.spr(index)->getUID();
25718 }
25719 585769 }
25720
25721
25722 5620654 void do_loaditemdata(const bool v)
25723 {
25724 5620654 int32_t ID = SH::get_arg(sarg1, v) / 10000;
25725
25726 //I *think* this is the right check ~Joe
25727
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5620654 times.
5620654 if(BC::checkItemID(ID) != SH::_NoError)
25728 {
25729 ri->idata = -1; //new null value
25730 return;
25731 }
25732 5620654 ri->idata = ID;
25733 5620654 }
25734
25735 27870027 void do_loadnpc(const bool v)
25736 {
25737 27870027 int32_t index = SH::get_arg(sarg1, v) / 10000;
25738
25739
2/2
✓ Branch 0 taken 204 times.
✓ Branch 1 taken 27869823 times.
27870027 if(BC::checkGuyIndex(index) != SH::_NoError)
25740 204 ri->guyref = 0; // MAX_DWORD;
25741 else
25742 {
25743 27869823 ri->guyref = guys.spr(index)->getUID();
25744 }
25745 27870027 }
25746
25747 1173684 void FFScript::do_loaddmapdata(const bool v)
25748 {
25749 1173684 int32_t ID = SH::get_arg(sarg1, v) / 10000;
25750
25751
2/4
✓ Branch 0 taken 1173684 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1173684 times.
1173684 if ( ID < 0 || ID > 511 )
25752 {
25753 Z_scripterrlog("Invalid DMap ID passed to Game->LoadDMapData(): %d\n", ID);
25754 ri->dmapsref = MAX_DWORD;
25755 }
25756 1173684 else ri->dmapsref = ID;
25757 1173684 }
25758
25759 3 void FFScript::do_load_active_subscreendata(const bool v)
25760 {
25761 3 int32_t ID = SH::get_arg(sarg1, v) / 10000;
25762
25763
3/6
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 if(ID == -1 || (unsigned(ID) < subscreens_active.size() && unsigned(ID) < 256))
25764 {
25765 3 ri->subdataref = get_subref(ID, sstACTIVE);
25766 3 }
25767 else
25768 {
25769 Z_scripterrlog("Invalid Subscreen ID passed to Game->LoadASubData(): %d\n", ID);
25770 ri->subdataref = 0;
25771 }
25772 3 ri->d[rEXP1] = ri->subdataref;
25773 3 }
25774 void FFScript::do_load_passive_subscreendata(const bool v)
25775 {
25776 int32_t ID = SH::get_arg(sarg1, v) / 10000;
25777
25778 if(ID == -1 || (unsigned(ID) < subscreens_passive.size() && unsigned(ID) < 256))
25779 {
25780 ri->subdataref = get_subref(ID, sstPASSIVE);
25781 }
25782 else
25783 {
25784 Z_scripterrlog("Invalid Subscreen ID passed to Game->LoadPSubData(): %d\n", ID);
25785 ri->subdataref = 0;
25786 }
25787 ri->d[rEXP1] = ri->subdataref;
25788 }
25789 void FFScript::do_load_overlay_subscreendata(const bool v)
25790 {
25791 int32_t ID = SH::get_arg(sarg1, v) / 10000;
25792
25793 if(ID == -1 || (unsigned(ID) < subscreens_overlay.size() && unsigned(ID) < 256))
25794 {
25795 ri->subdataref = get_subref(ID, sstOVERLAY);
25796 }
25797 else
25798 {
25799 Z_scripterrlog("Invalid Subscreen ID passed to Game->LoadOSubData(): %d\n", ID);
25800 ri->subdataref = 0;
25801 }
25802 ri->d[rEXP1] = ri->subdataref;
25803 }
25804 3 void FFScript::do_load_subscreendata(const bool v, const bool v2)
25805 {
25806 3 int32_t ty = SH::get_arg(sarg2, v2) / 10000;
25807
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 switch(ty)
25808 {
25809 case sstACTIVE:
25810 3 do_load_active_subscreendata(v);
25811 3 break;
25812 case sstPASSIVE:
25813 do_load_passive_subscreendata(v);
25814 break;
25815 case sstOVERLAY:
25816 do_load_overlay_subscreendata(v);
25817 break;
25818 default:
25819 {
25820 Z_scripterrlog("Invalid Subscreen Type passed to ???: %d\n", ty);
25821 ri->subdataref = 0;
25822 break;
25823 }
25824 }
25825 3 ri->d[rEXP1] = ri->subdataref;
25826 3 }
25827
25828 628 void FFScript::do_loadrng()
25829 {
25830 628 auto rng = user_rngs.create();
25831
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 628 times.
628 if (!rng)
25832 {
25833 ri->d[rEXP1] = 0;
25834 return;
25835 }
25836
25837 628 int q = script_object_ids_by_type[script_object_type::rng].size() - 1;
25838 628 rng->gen = &script_rnggens[q];
25839 628 ri->rngref = rng->id;
25840 628 ri->d[rEXP1] = rng->id;
25841 628 }
25842
25843 void FFScript::do_loaddirectory()
25844 {
25845 int32_t arrayptr = get_register(sarg1) / 10000;
25846 string user_path;
25847 ArrayH::getString(arrayptr, user_path, 2048);
25848
25849 std::string resolved_path;
25850 if (auto r = parse_user_path(user_path, false); !r)
25851 {
25852 scripting_log_error_with_context("Error: {}", r.error());
25853 return;
25854 } else resolved_path = r.value();
25855
25856 if (checkPath(resolved_path.c_str(), true))
25857 {
25858 ri->directoryref = user_dirs.get_free();
25859 if(!ri->directoryref) return;
25860 user_dir* d = checkDir(ri->directoryref, true);
25861 set_register(sarg1, ri->directoryref);
25862 d->setPath(resolved_path.c_str());
25863 return;
25864 }
25865
25866 scripting_log_error_with_context("Path '{}' points to a file; must point to a directory!", resolved_path);
25867 ri->directoryref = 0;
25868 set_register(sarg1, 0);
25869 }
25870
25871 void FFScript::do_loadstack()
25872 {
25873 ri->stackref = user_stacks.get_free();
25874 ri->d[rEXP1] = ri->stackref;
25875 }
25876
25877 10 void FFScript::do_loaddropset(const bool v)
25878 {
25879 10 int32_t ID = SH::get_arg(sarg1, v) / 10000;
25880
25881
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
10 if ( ID < 0 || ID > MAXITEMDROPSETS )
25882 {
25883 scripting_log_error_with_context("Invalid Dropset ID: {}", ID);
25884 ri->dropsetref = MAX_DWORD;
25885 }
25886
25887 10 else ri->dropsetref = ID;
25888 10 }
25889
25890 void FFScript::do_loadbottle(const bool v)
25891 {
25892 int32_t ID = SH::get_arg(sarg1, v) / 10000;
25893
25894 if ( ID < 1 || ID > 64 )
25895 {
25896 scripting_log_error_with_context("Invalid BottleType ID: {}", ID);
25897 ri->bottletyperef = 0;
25898 }
25899 else ri->bottletyperef = ID;
25900 }
25901
25902 void FFScript::do_loadbottleshop(const bool v)
25903 {
25904 int32_t ID = SH::get_arg(sarg1, v) / 10000;
25905
25906 if ( ID < 0 || ID > 255 )
25907 {
25908 scripting_log_error_with_context("Invalid BottleShopType ID: {}", ID);
25909 ri->bottleshopref = 0;
25910 }
25911 else ri->bottleshopref = ID+1;
25912 }
25913 137106 void FFScript::do_loadgenericdata(const bool v)
25914 {
25915 137106 int32_t ID = SH::get_arg(sarg1, v) / 10000;
25916
25917
2/4
✓ Branch 0 taken 137106 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 137106 times.
137106 if ( ID < 1 || ID > NUMSCRIPTSGENERIC )
25918 {
25919 scripting_log_error_with_context("Invalid GenericData ID: {}", ID);
25920 ri->genericdataref = 0;
25921 }
25922 137106 else ri->genericdataref = ID;
25923 137106 }
25924
25925 223 void FFScript::do_create_paldata()
25926 {
25927 223 ri->paldataref = user_paldatas.get_free();
25928 223 ri->d[rEXP1] = ri->paldataref;
25929 223 }
25930
25931 11 void FFScript::do_create_paldata_clr()
25932 {
25933 11 ri->paldataref = user_paldatas.get_free();
25934
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (ri->paldataref > 0)
25935 {
25936 11 user_paldata& pd = user_paldatas[ri->paldataref];
25937 11 int32_t clri = get_register(sarg1);
25938
25939 11 RGB c = _RGB((clri >> 16) & 0xFF, (clri >> 8) & 0xFF, clri & 0xFF);
25940
25941 11 c.r = vbound(c.r, 0, scripting_max_color_val);
25942 11 c.g = vbound(c.g, 0, scripting_max_color_val);
25943 11 c.b = vbound(c.b, 0, scripting_max_color_val);
25944
25945
2/2
✓ Branch 0 taken 2640 times.
✓ Branch 1 taken 11 times.
2651 for (int32_t q = 0; q < 240; ++q)
25946 2640 pd.set_color(q, c);
25947 11 }
25948 11 ri->d[rEXP1] = ri->paldataref;
25949 11 }
25950
25951 void FFScript::do_mix_clr()
25952 {
25953 int32_t clr_start = SH::read_stack(ri->sp + 3);
25954 int32_t clr_end = SH::read_stack(ri->sp + 2);
25955 float percent = SH::read_stack(ri->sp + 1) / 10000.0;
25956 int32_t color_space = SH::read_stack(ri->sp + 0) / 10000;
25957
25958 RGB ref1c = _RGB((clr_start >> 16) & 0xFF, (clr_start >> 8) & 0xFF, clr_start & 0xFF);
25959 RGB ref2c = _RGB((clr_end >> 16) & 0xFF, (clr_end >> 8) & 0xFF, clr_end & 0xFF);
25960 RGB outputc = user_paldata::mix_color(ref1c, ref2c, percent, color_space);
25961
25962 int32_t r = vbound(outputc.r, 0, scripting_max_color_val);
25963 int32_t g = vbound(outputc.g, 0, scripting_max_color_val);
25964 int32_t b = vbound(outputc.b, 0, scripting_max_color_val);
25965
25966 ri->d[rEXP1] = (r << 16) | (g << 8) | b;
25967 }
25968
25969 void FFScript::do_create_rgb_hex()
25970 {
25971 int32_t hexrgb = get_register(sarg1);
25972
25973 int32_t r = (hexrgb >> 16) & 0xFF;
25974 int32_t g = (hexrgb >> 8) & 0xFF;
25975 int32_t b = hexrgb & 0xFF;
25976
25977 if (scripting_use_8bit_colors)
25978 {
25979 r = vbound(r, 0, 255);
25980 g = vbound(g, 0, 255);
25981 b = vbound(b, 0, 255);
25982 }
25983 else
25984 {
25985 r = vbound(r / 4, 0, 63);
25986 g = vbound(g / 4, 0, 63);
25987 b = vbound(b / 4, 0, 63);
25988 }
25989
25990 ri->d[rEXP1] = (r << 16) | (g << 8) | b;
25991 }
25992
25993 11 void FFScript::do_create_rgb()
25994 {
25995 11 int32_t r = SH::read_stack(ri->sp + 2) / 10000;
25996 11 int32_t g = SH::read_stack(ri->sp + 1) / 10000;
25997 11 int32_t b = SH::read_stack(ri->sp + 0) / 10000;
25998
25999 11 int max_value = scripting_max_color_val;
26000
4/6
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
11 if (unsigned(r) > max_value || unsigned(g) > max_value || unsigned(b) > max_value)
26001 {
26002 1 scripting_log_error_with_context("R/G/B values should range from 0-{}", max_value);
26003 1 }
26004
26005 11 r = vbound(r, 0, max_value);
26006 11 g = vbound(g, 0, max_value);
26007 11 b = vbound(b, 0, max_value);
26008
26009 11 ri->d[rEXP1] = (r << 16) | (g << 8) | b;
26010 11 }
26011
26012 void FFScript::do_convert_from_rgb()
26013 {
26014 int32_t buf = SH::read_stack(ri->sp + 2) / 10000;
26015 int32_t clri = SH::read_stack(ri->sp + 1);
26016 int32_t color_space = SH::read_stack(ri->sp + 0) / 10000;
26017
26018 ArrayManager am(buf);
26019 if (am.invalid()) return;
26020 int32_t zscript_array_size = am.size();
26021 int32_t target_size;
26022
26023 switch (color_space)
26024 {
26025 case user_paldata::CSPACE_CMYK:
26026 target_size = 4;
26027 break;
26028 default:
26029 target_size = 3;
26030 }
26031
26032 if (zscript_array_size < target_size)
26033 {
26034 scripting_log_error_with_context("Array not large enough. Should be at least size {}", target_size);
26035 return;
26036 }
26037
26038 RGB c = _RGB((clri >> 16) & 0xFF, (clri >> 8) & 0xFF, clri & 0xFF);
26039 double convert[4];
26040 user_paldata::RGBTo(c, convert, color_space);
26041
26042 for (int32_t q = 0; q < target_size; ++q)
26043 {
26044 am.set(q, int32_t(convert[q]*10000));
26045 }
26046
26047 return;
26048 }
26049
26050 void FFScript::do_convert_to_rgb()
26051 {
26052 int32_t buf = SH::read_stack(ri->sp + 1) / 10000;
26053 int32_t color_space = SH::read_stack(ri->sp + 0) / 10000;
26054
26055 ArrayManager am(buf);
26056 if (am.invalid()) return;
26057 int32_t zscript_array_size = am.size();
26058 int32_t target_size;
26059
26060 switch (color_space)
26061 {
26062 case user_paldata::CSPACE_CMYK:
26063 target_size = 4;
26064 break;
26065 default:
26066 target_size = 3;
26067 }
26068
26069 if (zscript_array_size < target_size)
26070 {
26071 scripting_log_error_with_context("Array not large enough. Should be at least size {}", target_size);
26072 return;
26073 }
26074
26075 double convert[4];
26076 for (int32_t q = 0; q < target_size; ++q)
26077 {
26078 convert[q] = am.get(q) / 10000.0;
26079 }
26080 RGB c = user_paldata::RGBFrom(convert, color_space);
26081
26082 ri->d[rEXP1] = (c.r << 16) | (c.g << 8) | c.b;
26083 }
26084
26085 24 void FFScript::do_paldata_load_level()
26086 {
26087
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (user_paldata* pd = checkPalData(ri->paldataref))
26088 {
26089 24 int32_t lvl = get_register(sarg1) / 10000;
26090 //Load CSets 2-4
26091 24 pd->load_cset(2, lvl * pdLEVEL + poLEVEL + 0);
26092 24 pd->load_cset(3, lvl * pdLEVEL + poLEVEL + 1);
26093 24 pd->load_cset(4, lvl * pdLEVEL + poLEVEL + 2);
26094 //Load CSet 9
26095 24 pd->load_cset(9, lvl * pdLEVEL + poLEVEL + 3);
26096 //Load 1, 5, 7, 8
26097 24 pd->load_cset(1, lvl * pdLEVEL + poNEWCSETS);
26098 24 pd->load_cset(5, lvl * pdLEVEL + poNEWCSETS + 1);
26099 24 pd->load_cset(7, lvl * pdLEVEL + poNEWCSETS + 2);
26100 24 pd->load_cset(8, lvl * pdLEVEL + poNEWCSETS + 3);
26101 24 }
26102 24 return;
26103 }
26104
26105 87 void FFScript::do_paldata_load_sprite()
26106 {
26107
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 87 times.
87 if (user_paldata* pd = checkPalData(ri->paldataref))
26108 {
26109 87 int32_t page = get_register(sarg1) / 10000;
26110
26111 87 int32_t pageoffset = 0;
26112
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 87 times.
✗ Branch 2 not taken.
87 switch (page)
26113 {
26114 87 case 0: pageoffset += 0; break;
26115 case 1: pageoffset += 15; break;
26116 default:
26117 scripting_log_error_with_context("Invalid page: {}. Valid pages are 0 or 1. Aborting.", page);
26118 return;
26119 }
26120
2/2
✓ Branch 0 taken 1305 times.
✓ Branch 1 taken 87 times.
1392 for (int32_t q = 0; q < 15; ++q)
26121 {
26122 1305 pd->load_cset(q, poSPRITE255 + pageoffset + q);
26123 1305 }
26124 87 }
26125 87 return;
26126 87 }
26127
26128 92 void FFScript::do_paldata_load_main()
26129 {
26130
1/2
✓ Branch 0 taken 92 times.
✗ Branch 1 not taken.
92 if (user_paldata* pd = checkPalData(ri->paldataref))
26131 {
26132
2/2
✓ Branch 0 taken 1472 times.
✓ Branch 1 taken 92 times.
1564 for (int32_t q = 0; q <= 15; ++q)
26133 {
26134 1472 pd->load_cset_main(q);
26135 1472 }
26136 92 }
26137 92 return;
26138 }
26139
26140 void FFScript::do_paldata_load_cycle()
26141 {
26142 if (user_paldata* pd = checkPalData(ri->paldataref))
26143 {
26144 int32_t lvl = get_register(sarg1) / 10000;
26145 for (int32_t q = 4; q <= 12; ++q)
26146 {
26147 pd->load_cset(q, lvl * pdLEVEL + poLEVEL + q);
26148 }
26149 }
26150 return;
26151 }
26152
26153 void FFScript::do_paldata_load_bitmap()
26154 {
26155 if (user_paldata* pd = checkPalData(ri->paldataref))
26156 {
26157 int32_t pathptr = get_register(sarg1) / 10000;
26158 string user_path, str;
26159 ArrayH::getString(pathptr, user_path, 256);
26160
26161 if (get_qr(qr_BITMAP_AND_FILESYSTEM_PATHS_ALWAYS_RELATIVE))
26162 {
26163 if (auto r = parse_user_path(user_path, true); !r)
26164 {
26165 scripting_log_error_with_context("Error: {}", r.error());
26166 return;
26167 } else str = r.value();
26168 }
26169 else
26170 {
26171 str = user_path;
26172 regulate_path(str);
26173 }
26174
26175 if (str.empty())
26176 {
26177 al_trace("String pointer is null! Internal error. \n");
26178 return;
26179 }
26180
26181 PALETTE tempPal;
26182 get_palette(tempPal);
26183 if (checkPath(str.c_str(), false))
26184 {
26185 BITMAP* bmp = load_bitmap(str.c_str(), tempPal);
26186 if (!bmp)
26187 {
26188 Z_scripterrlog("LoadBitmapPalette() failed to load image file %s.\n", str.c_str());
26189 }
26190 else
26191 {
26192 for (int32_t q = 0; q < PALDATA_NUM_COLORS; ++q)
26193 {
26194 pd->colors[q] = tempPal[q];
26195 set_bit(pd->colors_used, q, true);
26196 }
26197 }
26198 destroy_bitmap(bmp);
26199 }
26200 else
26201 {
26202 Z_scripterrlog("Failed to load image file: %s. File not found.\n", str.c_str());
26203 }
26204 }
26205 return;
26206 }
26207
26208 370 void FFScript::do_paldata_write_level()
26209 {
26210
1/2
✓ Branch 0 taken 370 times.
✗ Branch 1 not taken.
370 if (user_paldata* pd = checkPalData(ri->paldataref))
26211 {
26212 370 int32_t lvl = get_register(sarg1) / 10000;
26213 370 bool changed = false;
26214 //Write CSets 2-4
26215
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(2, lvl * pdLEVEL + poLEVEL + 0))
26216 {
26217 360 pd->write_cset(2, lvl * pdLEVEL + poLEVEL + 0);
26218 360 changed = true;
26219 360 }
26220
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(3, lvl * pdLEVEL + poLEVEL + 1))
26221 {
26222 360 pd->write_cset(3, lvl * pdLEVEL + poLEVEL + 1);
26223 360 changed = true;
26224 360 }
26225
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(4, lvl * pdLEVEL + poLEVEL + 2))
26226 {
26227 360 pd->write_cset(4, lvl * pdLEVEL + poLEVEL + 2);
26228 360 changed = true;
26229 360 }
26230 //Write CSet 9
26231
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(9, lvl * pdLEVEL + poLEVEL + 3))
26232 {
26233 360 pd->write_cset(9, lvl * pdLEVEL + poLEVEL + 3);
26234 360 changed = true;
26235 360 }
26236 //Write 1, 5, 7, 8
26237
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(1, lvl * pdLEVEL + poNEWCSETS + 0))
26238 {
26239 360 pd->write_cset(1, lvl * pdLEVEL + poNEWCSETS + 0);
26240 360 changed = true;
26241 360 }
26242
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(5, lvl * pdLEVEL + poNEWCSETS + 1))
26243 {
26244 360 pd->write_cset(5, lvl * pdLEVEL + poNEWCSETS + 1);
26245 360 changed = true;
26246 360 }
26247
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(7, lvl * pdLEVEL + poNEWCSETS + 2))
26248 {
26249 360 pd->write_cset(7, lvl * pdLEVEL + poNEWCSETS + 2);
26250 360 changed = true;
26251 360 }
26252
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(8, lvl * pdLEVEL + poNEWCSETS + 3))
26253 {
26254 360 pd->write_cset(8, lvl * pdLEVEL + poNEWCSETS + 3);
26255 360 changed = true;
26256 360 }
26257
26258
4/4
✓ Branch 0 taken 360 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 350 times.
370 if (changed && DMaps[cur_dmap].color == lvl)
26259 {
26260 350 loadlvlpal(lvl);
26261 350 currcset = lvl;
26262
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 350 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
350 if (darkroom && !get_qr(qr_NEW_DARKROOM))
26263 {
26264 if (get_qr(qr_FADE))
26265 {
26266 interpolatedfade();
26267 }
26268 else
26269 {
26270 loadfadepal((DMaps[cur_dmap].color) * pdLEVEL + poFADE3);
26271 }
26272 }
26273 350 }
26274 370 }
26275 370 return;
26276 }
26277
26278 void FFScript::do_paldata_write_levelcset()
26279 {
26280 if (user_paldata* pd = checkPalData(ri->paldataref))
26281 {
26282 int32_t lvl = get_register(sarg1) / 10000;
26283 int32_t cs = get_register(sarg2) / 10000;
26284
26285 bool changed = false;
26286
26287 switch (cs)
26288 {
26289 case 1:
26290 if (pd->check_cset(1, lvl * pdLEVEL + poNEWCSETS + 0))
26291 {
26292 pd->write_cset(1, lvl * pdLEVEL + poNEWCSETS + 0);
26293 changed = true;
26294 }
26295 break;
26296 case 2:
26297 if (pd->check_cset(2, lvl * pdLEVEL + poLEVEL + 0))
26298 {
26299 pd->write_cset(2, lvl * pdLEVEL + poLEVEL + 0);
26300 changed = true;
26301 }
26302 break;
26303 case 3:
26304 if (pd->check_cset(3, lvl * pdLEVEL + poLEVEL + 1))
26305 {
26306 pd->write_cset(3, lvl * pdLEVEL + poLEVEL + 1);
26307 changed = true;
26308 }
26309 break;
26310 case 4:
26311 if (pd->check_cset(4, lvl * pdLEVEL + poLEVEL + 2))
26312 {
26313 pd->write_cset(4, lvl * pdLEVEL + poLEVEL + 2);
26314 changed = true;
26315 }
26316 break;
26317 case 5:
26318 if (pd->check_cset(5, lvl * pdLEVEL + poNEWCSETS + 1))
26319 {
26320 pd->write_cset(5, lvl * pdLEVEL + poNEWCSETS + 1);
26321 changed = true;
26322 }
26323 break;
26324 case 7:
26325 if (pd->check_cset(7, lvl * pdLEVEL + poNEWCSETS + 2))
26326 {
26327 pd->write_cset(7, lvl * pdLEVEL + poNEWCSETS + 2);
26328 changed = true;
26329 }
26330 break;
26331 case 8:
26332 if (pd->check_cset(8, lvl * pdLEVEL + poNEWCSETS + 3))
26333 {
26334 pd->write_cset(8, lvl * pdLEVEL + poNEWCSETS + 3);
26335 changed = true;
26336 }
26337 break;
26338 case 9:
26339 if (pd->check_cset(9, lvl * pdLEVEL + poLEVEL + 3))
26340 {
26341 pd->write_cset(9, lvl * pdLEVEL + poLEVEL + 3);
26342 changed = true;
26343 }
26344 break;
26345 default:
26346 Z_scripterrlog("Invalid CSet (%d) passed to 'paldata->WriteLevelCSet()'. Level palettes can use CSets 1, 2, 3, 4, 5, 7, 8, 9.\n");
26347 return;
26348 }
26349
26350 if (changed && DMaps[cur_dmap].color == lvl)
26351 {
26352 loadlvlpal(lvl);
26353 if (darkroom && !get_qr(qr_NEW_DARKROOM))
26354 {
26355 if (get_qr(qr_FADE))
26356 {
26357 interpolatedfade();
26358 }
26359 else
26360 {
26361 loadfadepal((DMaps[cur_dmap].color) * pdLEVEL + poFADE3);
26362 }
26363 }
26364 currcset = lvl;
26365 }
26366 }
26367 }
26368
26369 31 void FFScript::do_paldata_write_sprite()
26370 {
26371
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
31 if (user_paldata* pd = checkPalData(ri->paldataref))
26372 {
26373 31 int32_t page = get_register(sarg1) / 10000;
26374
26375 31 int32_t pageoffset = 0;
26376
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
31 switch (page)
26377 {
26378 31 case 0: pageoffset += 0; break;
26379 case 1: pageoffset += 15; break;
26380 default:
26381 Z_scripterrlog("Invalid page (%d) passed to paldata->WriteSpritePalette(). Valid pages are 0 or 1. Aborting.\n", page);
26382 return;
26383 }
26384 31 bool changed6 = false;
26385 31 bool changed14 = false;
26386
2/2
✓ Branch 0 taken 465 times.
✓ Branch 1 taken 31 times.
496 for (int32_t q = 0; q < 15; ++q)
26387 {
26388
2/2
✓ Branch 0 taken 440 times.
✓ Branch 1 taken 25 times.
465 if (pd->check_cset(q, poSPRITE255 + pageoffset + q))
26389 {
26390 25 pd->write_cset(q, poSPRITE255 + pageoffset + q);
26391
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 if (pageoffset + q == currspal6)
26392 {
26393 changed6 = true;
26394 }
26395
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 if (pageoffset + q == currspal14)
26396 {
26397 changed14 = true;
26398 }
26399 25 }
26400 465 }
26401
26402 //If either sprite palette has been changed, update the main palette
26403
2/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31 times.
31 if (changed6 || changed14)
26404 {
26405 if (changed6)
26406 {
26407 loadpalset(6, poSPRITE255 + currspal6, false);
26408 }
26409 if (changed14)
26410 {
26411 loadpalset(14, poSPRITE255 + currspal14, false);
26412 }
26413
26414 if (isUserTinted()) {
26415 restoreTint();
26416 }
26417 }
26418 31 }
26419 31 return;
26420 31 }
26421
26422 void FFScript::do_paldata_write_spritecset()
26423 {
26424 if (user_paldata* pd = checkPalData(ri->paldataref))
26425 {
26426 int32_t page = get_register(sarg1) / 10000;
26427 int32_t cs = get_register(sarg2) / 10000;
26428
26429 int32_t pageoffset = 0;
26430 switch (page)
26431 {
26432 case 0: pageoffset += 0; break;
26433 case 1: pageoffset += 15; break;
26434 default:
26435 Z_scripterrlog("Invalid page (%d) passed to paldata->WriteSpriteCSet(). Valid pages are 0 or 1. Aborting.\n", page);
26436 return;
26437 }
26438 bool changed6 = false;
26439 bool changed14 = false;
26440 if (unsigned(cs) > 15)
26441 {
26442 Z_scripterrlog("Invalid CSet (%d) passed to paldata->WriteSpriteCSet(). Valid CSets are 0-15. Aborting.\n", cs);
26443 return;
26444 }
26445 if (pd->check_cset(cs, poSPRITE255 + pageoffset + cs))
26446 {
26447 pd->write_cset(cs, poSPRITE255 + pageoffset + cs);
26448 if (pageoffset + cs == currspal6)
26449 {
26450 changed6 = true;
26451 }
26452 if (pageoffset + cs == currspal14)
26453 {
26454 changed14 = true;
26455 }
26456 }
26457
26458 //If either sprite palette has been changed, update the main palette
26459 if (changed6 || changed14)
26460 {
26461 if (changed6)
26462 {
26463 loadpalset(6, poSPRITE255 + currspal6, false);
26464 }
26465 if (changed14)
26466 {
26467 loadpalset(14, poSPRITE255 + currspal14, false);
26468 }
26469
26470 if (isUserTinted()) {
26471 restoreTint();
26472 }
26473 }
26474 }
26475 return;
26476 }
26477
26478 1064 void FFScript::do_paldata_write_main()
26479 {
26480
1/2
✓ Branch 0 taken 1064 times.
✗ Branch 1 not taken.
1064 if (user_paldata* pd = checkPalData(ri->paldataref))
26481 {
26482 1064 bool changed = false;
26483
2/2
✓ Branch 0 taken 17024 times.
✓ Branch 1 taken 1064 times.
18088 for (int32_t q = 0; q <= 15; ++q)
26484 {
26485
2/2
✓ Branch 0 taken 11363 times.
✓ Branch 1 taken 5661 times.
17024 if (pd->check_cset_main(q))
26486 {
26487 5661 pd->write_cset_main(q);
26488 5661 changed = true;
26489 5661 }
26490 17024 }
26491
26492
2/2
✓ Branch 0 taken 332 times.
✓ Branch 1 taken 732 times.
1064 if (changed)
26493 {
26494 732 refreshpal = true;
26495 732 }
26496 1064 }
26497 1064 return;
26498 }
26499
26500 130 void FFScript::do_paldata_write_maincset()
26501 {
26502
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
130 if (user_paldata* pd = checkPalData(ri->paldataref))
26503 {
26504 130 int32_t cs = get_register(sarg1) / 10000;
26505
26506 130 bool changed = false;
26507
26508
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (unsigned(cs) < 16)
26509 {
26510
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (pd->check_cset_main(cs))
26511 {
26512 130 pd->write_cset_main(cs);
26513 130 changed = true;
26514 130 }
26515 130 }
26516 else
26517 {
26518 Z_scripterrlog("Invalid CSet (%d) passed to 'paldata->WriteMainCSet()'. Valid csets are 0-15. Aborting.\n");
26519 return;
26520 }
26521
26522
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (changed)
26523 {
26524 130 refreshpal = true;
26525 130 }
26526 130 }
26527 130 }
26528
26529 void FFScript::do_paldata_write_cycle()
26530 {
26531 if (user_paldata* pd = checkPalData(ri->paldataref))
26532 {
26533 int32_t lvl = get_register(sarg1) / 10000;
26534 for (int32_t q = 4; q <= 12; ++q)
26535 {
26536 if (pd->check_cset(q, lvl * pdLEVEL + poLEVEL + q))
26537 {
26538 pd->write_cset(q, lvl * pdLEVEL + poLEVEL + q);
26539 }
26540 }
26541 }
26542 return;
26543 }
26544
26545 void FFScript::do_paldata_write_cyclecset()
26546 {
26547 if (user_paldata* pd = checkPalData(ri->paldataref))
26548 {
26549 int32_t lvl = get_register(sarg1) / 10000;
26550 int32_t cs = get_register(sarg2) / 10000;
26551
26552 bool changed = false;
26553
26554 switch (cs)
26555 {
26556 case 4:
26557 case 5:
26558 case 6:
26559 case 7:
26560 case 8:
26561 case 9:
26562 case 10:
26563 case 11:
26564 case 12:
26565 if (pd->check_cset(cs, lvl * pdLEVEL + poLEVEL + cs))
26566 {
26567 pd->write_cset(cs, lvl * pdLEVEL + poLEVEL + cs);
26568 changed = true;
26569 }
26570 break;
26571 default:
26572 Z_scripterrlog("Invalid CSet (%d) passed to 'paldata->WriteCycleCSet()'. Cycle palettes use CSets 4-12.\n");
26573 return;
26574 }
26575
26576 if (changed && DMaps[cur_dmap].color == lvl)
26577 {
26578 loadlvlpal(lvl);
26579 currcset = lvl;
26580 }
26581 }
26582 }
26583
26584 void FFScript::do_paldata_colorvalid()
26585 {
26586 if (user_paldata* pd = checkPalData(ri->paldataref))
26587 {
26588 int32_t ind = get_register(sarg1) / 10000;
26589 if (unsigned(ind) >= PALDATA_NUM_COLORS)
26590 {
26591 Z_scripterrlog("Invalid color index (%d) passed to paldata->ColorValid(). Valid indices are 0-255.\n", ind);
26592 set_register(sarg1, 0);
26593 return;
26594 }
26595
26596 if (get_bit(pd->colors_used, ind))
26597 {
26598 set_register(sarg1, 10000);
26599 }
26600 else
26601 {
26602 set_register(sarg1, 0);
26603 }
26604 }
26605 }
26606
26607 void FFScript::do_paldata_clearcolor()
26608 {
26609 if (user_paldata* pd = checkPalData(ri->paldataref))
26610 {
26611 int32_t ind = get_register(sarg1) / 10000;
26612 if (unsigned(ind) >= PALDATA_NUM_COLORS)
26613 {
26614 Z_scripterrlog("Invalid color index (%d) passed to paldata->ClearColor(). Valid indices are 0-255. Aborting.\n", ind);
26615 return;
26616 }
26617 set_bit(pd->colors_used, ind, false);
26618 }
26619 }
26620
26621 void FFScript::do_paldata_clearcset()
26622 {
26623 if (user_paldata* pd = checkPalData(ri->paldataref))
26624 {
26625 int32_t cs = get_register(sarg1) / 10000;
26626 if (unsigned(cs) > 15)
26627 {
26628 Z_scripterrlog("Invalid cset (%d) passed to paldata->ClearCSet(). Valid csets are 0-15. Aborting.\n", cs);
26629 return;
26630 }
26631 for (int32_t q = 0; q < 16; ++q)
26632 {
26633 set_bit(pd->colors_used, CSET(cs) + q, false);
26634 }
26635 }
26636 }
26637
26638 int32_t FFScript::do_paldata_getrgb(int32_t v)
26639 {
26640 if (user_paldata* pd = checkPalData(ri->paldataref))
26641 {
26642 int32_t ind = ri->d[rINDEX] / 10000;
26643 if (unsigned(ind) >= PALDATA_NUM_COLORS)
26644 {
26645 scripting_log_error_with_context("Invalid color index ({}). Valid indices are 0-255.", ind);
26646 return -10000;
26647 }
26648 if (!get_bit(pd->colors_used, ind))
26649 {
26650 scripting_log_error_with_context("Tried to access unused color {}.", ind);
26651 return -10000;
26652 }
26653 switch (v)
26654 {
26655 case 0:
26656 return pd->colors[ind].r * 10000;
26657 case 1:
26658 return pd->colors[ind].g * 10000;
26659 case 2:
26660 return pd->colors[ind].b * 10000;
26661 }
26662 }
26663 return -10000;
26664 }
26665
26666 void FFScript::do_paldata_setrgb(int32_t v, int32_t val)
26667 {
26668 if (user_paldata* pd = checkPalData(ri->paldataref))
26669 {
26670 int32_t ind = ri->d[rINDEX] / 10000;
26671 if (unsigned(ind) >= PALDATA_NUM_COLORS)
26672 {
26673 scripting_log_error_with_context("Invalid color index ({})Valid indices are 0-255. Aborting.", ind);
26674 return;
26675 }
26676 if (unsigned(val) > scripting_max_color_val)
26677 {
26678 scripting_log_error_with_context("RGB value({}) is out of range. RGB values range from 0 - {}.", val, scripting_max_color_val);
26679 val = vbound(val, 0, scripting_max_color_val);
26680 }
26681 if (!get_bit(pd->colors_used, ind))
26682 {
26683 scripting_log_error_with_context("Tried to access unused color {}.", ind);
26684 return;
26685 }
26686 switch (v)
26687 {
26688 case 0:
26689 pd->colors[ind].r = val;
26690 break;
26691 case 1:
26692 pd->colors[ind].g = val;
26693 break;
26694 case 2:
26695 pd->colors[ind].b = val;
26696 break;
26697 }
26698 }
26699 }
26700
26701 450 void FFScript::do_paldata_mix()
26702 {
26703 450 int32_t ref = SH::read_stack(ri->sp + 4);
26704
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 450 times.
450 if (user_paldata* pd = checkPalData(ref))
26705 {
26706 450 int32_t ref1 = SH::read_stack(ri->sp + 3);
26707 450 int32_t ref2 = SH::read_stack(ri->sp + 2);
26708 450 double percent = SH::read_stack(ri->sp + 1)/10000.0;
26709 450 int32_t color_space = SH::read_stack(ri->sp + 0)/10000;
26710
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 450 times.
450 if (user_paldata* pd_start = checkPalData(ref1))
26711 {
26712
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 450 times.
450 if (user_paldata* pd_end = checkPalData(ref2))
26713 {
26714 450 pd->mix(pd_start, pd_end, percent, color_space);
26715 450 }
26716 450 }
26717 450 }
26718 450 }
26719
26720 4781 void FFScript::do_paldata_mixcset()
26721 {
26722 4781 int32_t ref = SH::read_stack(ri->sp + 5);
26723
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4781 times.
4781 if (user_paldata* pd = checkPalData(ref))
26724 {
26725 4781 int32_t ref1 = SH::read_stack(ri->sp + 4);
26726 4781 int32_t ref2 = SH::read_stack(ri->sp + 3);
26727 4781 int32_t cset = SH::read_stack(ri->sp + 2) / 10000;
26728 4781 double percent = SH::read_stack(ri->sp + 1) / 10000.0;
26729 4781 int32_t color_space = SH::read_stack(ri->sp + 0) / 10000;
26730
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4781 times.
4781 if (user_paldata* pd_start = checkPalData(ref1))
26731 {
26732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4781 times.
4781 if (user_paldata* pd_end = checkPalData(ref2))
26733 {
26734
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4781 times.
4781 if (unsigned(cset) > 15)
26735 {
26736 Z_scripterrlog("CSet passed to 'paldata->MixCSet()' out of range. Valid CSets are 0-15\n");
26737 return;
26738 }
26739 4781 pd->mix(pd_start, pd_end, percent, color_space, CSET(cset), CSET(cset) + 16);
26740 4781 }
26741 4781 }
26742 4781 }
26743 4781 }
26744
26745 void FFScript::do_paldata_copy()
26746 {
26747 if (user_paldata* pd = checkPalData(ri->paldataref))
26748 {
26749 int32_t ref_dest = get_register(sarg1);
26750 if (user_paldata* pd_dest = checkPalData(ref_dest))
26751 {
26752 for (int32_t q = 0; q < PALDATA_NUM_COLORS; ++q)
26753 {
26754 pd_dest->colors[q] = pd->colors[q];
26755 }
26756 for (int32_t q = 0; q < PALDATA_BITSTREAM_SIZE; ++q)
26757 {
26758 pd_dest->colors_used[q] = pd->colors_used[q];
26759 }
26760 }
26761 }
26762 }
26763
26764 112 void FFScript::do_paldata_copycset()
26765 {
26766 112 ri->paldataref = SH::read_stack(ri->sp + 3);
26767
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
112 if (user_paldata* pd = checkPalData(ri->paldataref))
26768 {
26769 112 int32_t ref_dest = SH::read_stack(ri->sp + 2);
26770 112 int32_t cs = SH::read_stack(ri->sp + 1) / 10000;
26771 112 int32_t cs_dest = SH::read_stack(ri->sp + 0) / 10000;
26772
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
112 if (user_paldata* pd_dest = checkPalData(ref_dest))
26773 {
26774
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
112 if (unsigned(cs) > 15)
26775 {
26776 Z_scripterrlog("Invalid CSet (%d) passed to paldata->CopyCSet(). Valid CSets are 0-15. Aborting.\n", cs);
26777 return;
26778 }
26779
2/2
✓ Branch 0 taken 1792 times.
✓ Branch 1 taken 112 times.
1904 for (int32_t q = 0; q < 16; ++q)
26780 {
26781 1792 pd_dest->colors[CSET(cs_dest) + q] = pd->colors[CSET(cs) + q];
26782 1792 set_bit(pd_dest->colors_used, CSET(cs_dest) + q, bool(get_bit(pd->colors_used, CSET(cs) + q)));
26783 1792 }
26784 112 }
26785 112 }
26786 112 }
26787
26788 //Loads a cset to paldata from memory
26789 1497 void user_paldata::load_cset(int32_t cset, int32_t dataset)
26790 {
26791 1497 byte* si = colordata + CSET(dataset) * 3;
26792
2/2
✓ Branch 0 taken 23952 times.
✓ Branch 1 taken 1497 times.
25449 for (int32_t q = 0; q < 16; ++q)
26793 {
26794 23952 int32_t ind = CSET(cset) + q;
26795 23952 colors[ind].r = scripting_read_pal_color(si[0]);
26796 23952 colors[ind].g = scripting_read_pal_color(si[1]);
26797 23952 colors[ind].b = scripting_read_pal_color(si[2]);
26798 23952 set_bit(colors_used, ind, true);
26799 23952 si += 3;
26800 23952 }
26801 1497 }
26802
26803 //Loads a cset to paldata from the main palette
26804 1472 void user_paldata::load_cset_main(int32_t cset)
26805 {
26806
2/2
✓ Branch 0 taken 23552 times.
✓ Branch 1 taken 1472 times.
25024 for (int32_t q = 0; q < 16; ++q)
26807 {
26808 23552 int32_t ind = CSET(cset) + q;
26809 23552 colors[ind].r = scripting_read_pal_color(RAMpal[ind].r);
26810 23552 colors[ind].g = scripting_read_pal_color(RAMpal[ind].g);
26811 23552 colors[ind].b = scripting_read_pal_color(RAMpal[ind].b);
26812 23552 set_bit(colors_used, ind, true);
26813 23552 }
26814 1472 }
26815
26816 //Writes to a memory cset from paldata
26817 2905 void user_paldata::write_cset(int32_t cset, int32_t dataset)
26818 {
26819 2905 byte* si = colordata + CSET(dataset) * 3;
26820
2/2
✓ Branch 0 taken 46480 times.
✓ Branch 1 taken 2905 times.
49385 for (int32_t q = 0; q < 16; ++q)
26821 {
26822 46480 int32_t ind = CSET(cset) + q;
26823
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46480 times.
46480 if (get_bit(colors_used, ind))
26824 {
26825 46480 si[0] = scripting_write_pal_color(colors[ind].r);
26826 46480 si[1] = scripting_write_pal_color(colors[ind].g);
26827 46480 si[2] = scripting_write_pal_color(colors[ind].b);
26828 46480 }
26829 46480 si += 3;
26830 46480 }
26831 2905 }
26832
26833 //Writes to a main palette cset from paldata
26834 5791 void user_paldata::write_cset_main(int32_t cset)
26835 {
26836
2/2
✓ Branch 0 taken 92656 times.
✓ Branch 1 taken 5791 times.
98447 for (int32_t q = 0; q < 16; ++q)
26837 {
26838 92656 int32_t ind = CSET(cset) + q;
26839
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92656 times.
92656 if (get_bit(colors_used, ind))
26840 {
26841 92656 RAMpal[ind] = colors[ind];
26842
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92656 times.
92656 if (!scripting_use_8bit_colors)
26843 92656 convertRGB(RAMpal[ind]);
26844 92656 }
26845 92656 }
26846 5791 }
26847
26848
26849 //Checks a memory cset from
26850
26851
26852
26853
26854 3425 bool user_paldata::check_cset(int32_t cset, int32_t dataset)
26855 {
26856 3425 byte* si = colordata + CSET(dataset) * 3;
26857
2/2
✓ Branch 0 taken 11375 times.
✓ Branch 1 taken 520 times.
11895 for (int32_t q = 0; q < 16; ++q)
26858 {
26859 11375 int32_t ind = CSET(cset) + q;
26860
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11375 times.
11375 if (get_bit(colors_used, ind))
26861 {
26862
2/2
✓ Branch 0 taken 9482 times.
✓ Branch 1 taken 1893 times.
11375 if (scripting_read_pal_color(si[0]) != colors[ind].r)
26863 1893 return true;
26864
2/2
✓ Branch 0 taken 8470 times.
✓ Branch 1 taken 1012 times.
9482 if (scripting_read_pal_color(si[1]) != colors[ind].g)
26865 1012 return true;
26866
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8470 times.
8470 if (scripting_read_pal_color(si[2]) != colors[ind].b)
26867 return true;
26868 8470 }
26869 8470 si += 3;
26870 8470 }
26871 520 return false;
26872 3425 }
26873
26874 //Checks a memory cset from the main palette
26875 17154 bool user_paldata::check_cset_main(int32_t cset)
26876 {
26877
2/2
✓ Branch 0 taken 188844 times.
✓ Branch 1 taken 11363 times.
200207 for (int32_t q = 0; q < 16; ++q)
26878 {
26879 188844 int32_t ind = CSET(cset) + q;
26880
2/2
✓ Branch 0 taken 96064 times.
✓ Branch 1 taken 92780 times.
188844 if (get_bit(colors_used, ind))
26881 {
26882
2/2
✓ Branch 0 taken 88937 times.
✓ Branch 1 taken 3843 times.
92780 if (scripting_read_pal_color(RAMpal[ind].r) != colors[ind].r)
26883 3843 return true;
26884
2/2
✓ Branch 0 taken 87200 times.
✓ Branch 1 taken 1737 times.
88937 if (scripting_read_pal_color(RAMpal[ind].g) != colors[ind].g)
26885 1737 return true;
26886
2/2
✓ Branch 0 taken 211 times.
✓ Branch 1 taken 86989 times.
87200 if (scripting_read_pal_color(RAMpal[ind].b) != colors[ind].b)
26887 211 return true;
26888 86989 }
26889 183053 }
26890 11363 return false;
26891 17154 }
26892
26893 //Mixes a color between two paldatas
26894 139696 RGB user_paldata::mix_color(RGB start, RGB end, double percent, int32_t color_space)
26895 {
26896 139696 double upper = scripting_max_color_val;
26897 139696 int32_t direction = 0;
26898
1/13
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 139696 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
139696 switch (color_space)
26899 {
26900 case CSPACE_RGB:
26901 279392 return _RGB(byte(vbound(double(zc::math::Lerp(start.r, end.r, percent)), 0.0, upper)),
26902 139696 byte(vbound(double(zc::math::Lerp(start.g, end.g, percent)), 0.0, upper)),
26903 139696 byte(vbound(double(zc::math::Lerp(start.b, end.b, percent)), 0.0, upper)));
26904 case CSPACE_CMYK:
26905 {
26906 double convert_start[4];
26907 double convert_end[4];
26908 double convert_result[4];
26909 RGBTo(start, convert_start, color_space);
26910 RGBTo(end, convert_end, color_space);
26911 convert_result[0] = zc::math::Lerp(convert_start[0], convert_end[0], percent);
26912 convert_result[1] = zc::math::Lerp(convert_start[1], convert_end[1], percent);
26913 convert_result[2] = zc::math::Lerp(convert_start[2], convert_end[2], percent);
26914 convert_result[3] = zc::math::Lerp(convert_start[3], convert_end[3], percent);
26915 return RGBFrom(convert_result, color_space);
26916 }
26917 case CSPACE_HSV_CW:
26918 if (color_space == CSPACE_HSV_CW)
26919 direction = 1;
26920 [[fallthrough]];
26921 case CSPACE_HSV_CCW:
26922 if (color_space == CSPACE_HSV_CCW)
26923 direction = -1;
26924 [[fallthrough]];
26925 case CSPACE_HSV:
26926 {
26927 double convert_start[3];
26928 double convert_end[3];
26929 double convert_result[3];
26930 RGBTo(start, convert_start, color_space);
26931 RGBTo(end, convert_end, color_space);
26932 convert_result[0] = WrapLerp(convert_start[0], convert_end[0], percent, 0.0, 1.0, direction);
26933 convert_result[1] = zc::math::Lerp(convert_start[1], convert_end[1], percent);
26934 convert_result[2] = zc::math::Lerp(convert_start[2], convert_end[2], percent);
26935 return RGBFrom(convert_result, color_space);
26936 }
26937 case CSPACE_HSL_CW:
26938 if (color_space == CSPACE_HSL_CW)
26939 direction = 1;
26940 [[fallthrough]];
26941 case CSPACE_HSL_CCW:
26942 if (color_space == CSPACE_HSL_CCW)
26943 direction = -1;
26944 [[fallthrough]];
26945 case CSPACE_HSL:
26946 {
26947 double convert_start[3];
26948 double convert_end[3];
26949 double convert_result[3];
26950 RGBTo(start, convert_start, color_space);
26951 RGBTo(end, convert_end, color_space);
26952 convert_result[0] = WrapLerp(convert_start[0], convert_end[0], percent, 0.0, 1.0, direction);
26953 convert_result[1] = zc::math::Lerp(convert_start[1], convert_end[1], percent);
26954 convert_result[2] = zc::math::Lerp(convert_start[2], convert_end[2], percent);
26955 return RGBFrom(convert_result, color_space);
26956 }
26957 case CSPACE_LAB:
26958 {
26959 double convert_start[3];
26960 double convert_end[3];
26961 double convert_result[3];
26962 RGBTo(start, convert_start, color_space);
26963 RGBTo(end, convert_end, color_space);
26964 convert_result[0] = zc::math::Lerp(convert_start[0], convert_end[0], percent);
26965 convert_result[1] = zc::math::Lerp(convert_start[1], convert_end[1], percent);
26966 convert_result[2] = zc::math::Lerp(convert_start[2], convert_end[2], percent);
26967 return RGBFrom(convert_result, color_space);
26968 }
26969 case CSPACE_LCH_CW:
26970 if (color_space == CSPACE_LCH_CW)
26971 direction = 1;
26972 [[fallthrough]];
26973 case CSPACE_LCH_CCW:
26974 if (color_space == CSPACE_LCH_CCW)
26975 direction = -1;
26976 [[fallthrough]];
26977 case CSPACE_LCH:
26978 {
26979 double convert_start[3];
26980 double convert_end[3];
26981 double convert_result[3];
26982 RGBTo(start, convert_start, color_space);
26983 RGBTo(end, convert_end, color_space);
26984 convert_result[0] = zc::math::Lerp(convert_start[0], convert_end[0], percent);
26985 convert_result[1] = zc::math::Lerp(convert_start[1], convert_end[1], percent);
26986 convert_result[2] = WrapLerp(convert_start[2], convert_end[2], percent, 0.0, 360.0, direction);
26987 return RGBFrom(convert_result, color_space);
26988 }
26989 }
26990 return start;
26991 139696 }
26992
26993 void user_paldata::RGBTo(RGB c, double arr[], int32_t color_space)
26994 {
26995 //From easyrgb.com/en/math.php
26996 double upper = scripting_max_color_val;
26997 double r = vbound(c.r / upper, 0.0, 1.0);
26998 double g = vbound(c.g / upper, 0.0, 1.0);
26999 double b = vbound(c.b / upper, 0.0, 1.0);
27000 switch (color_space)
27001 {
27002 case CSPACE_CMYK:
27003 {
27004 double c = 1.0 - r;
27005 double m = 1.0 - g;
27006 double y = 1.0 - b;
27007
27008 double k = 1.0;
27009
27010 if (c < k) k = c;
27011 if (m < k) k = m;
27012 if (y < k) k = y;
27013 if (k == 1)
27014 {
27015 c = 0.0;
27016 m = 0.0;
27017 y = 0.0;
27018 }
27019 else
27020 {
27021 c = (c - k) / (1.0 - k);
27022 m = (m - k) / (1.0 - k);
27023 y = (y - k) / (1.0 - k);
27024 }
27025 arr[0] = c;
27026 arr[1] = m;
27027 arr[2] = y;
27028 arr[3] = k;
27029 break;
27030 }
27031 case CSPACE_HSV_CW:
27032 case CSPACE_HSV_CCW:
27033 case CSPACE_HSV:
27034 {
27035 double min_val = std::min(std::min(r, g), b);
27036 double max_val = std::max(std::max(r, g), b);
27037 double del_max = max_val - min_val;
27038
27039 double h = 0;
27040 double s = 0;
27041 double v = max_val;
27042
27043 if (del_max != 0) //Set chroma if not gray
27044 {
27045 s = del_max / max_val;
27046
27047 double del_r = (((max_val - r) / 6.0) + (del_max / 2.0)) / del_max;
27048 double del_g = (((max_val - g) / 6.0) + (del_max / 2.0)) / del_max;
27049 double del_b = (((max_val - b) / 6.0) + (del_max / 2.0)) / del_max;
27050
27051 if (r == max_val) h = del_b - del_g;
27052 else if (g == max_val) h = (1.0 / 3.0) + del_r - del_b;
27053 else if (b == max_val) h = (2.0 / 3.0) + del_g - del_r;
27054
27055 if (h < 0) ++h;
27056 if (h > 1) --h;
27057 }
27058
27059 arr[0] = h;
27060 arr[1] = s;
27061 arr[2] = v;
27062 break;
27063 }
27064 case CSPACE_HSL_CW:
27065 case CSPACE_HSL_CCW:
27066 case CSPACE_HSL:
27067 {
27068 double min_val = std::min(std::min(r, g), b);
27069 double max_val = std::max(std::max(r, g), b);
27070 double del_max = max_val - min_val;
27071
27072 double h = 0;
27073 double s = 0;
27074 double l = (max_val + min_val) / 2.0;
27075
27076 if (del_max != 0) //Set chroma if not gray
27077 {
27078 if (l < 0.5) s = del_max / (max_val + min_val);
27079 else s = del_max / (2 - max_val - min_val);
27080
27081 double del_r = (((max_val - r) / 6.0) + (del_max / 2.0)) / del_max;
27082 double del_g = (((max_val - g) / 6.0) + (del_max / 2.0)) / del_max;
27083 double del_b = (((max_val - b) / 6.0) + (del_max / 2.0)) / del_max;
27084
27085 if (r == max_val) h = del_b - del_g;
27086 else if (g == max_val) h = (1.0 / 3.0) + del_r - del_b;
27087 else if (b == max_val) h = (2.0 / 3.0) + del_g - del_r;
27088
27089 if (h < 0) ++h;
27090 if (h > 1) --h;
27091 }
27092
27093 arr[0] = h;
27094 arr[1] = s;
27095 arr[2] = l;
27096 break;
27097 }
27098 case CSPACE_LAB:
27099 {
27100 if (r > 0.04045) r = pow(((r + 0.055) / 1.055), 2.4);
27101 else r /= 12.92;
27102 if (g > 0.04045) g = pow(((g + 0.055) / 1.055), 2.4);
27103 else g /= 12.92;
27104 if (b > 0.04045) b = pow(((b + 0.055) / 1.055), 2.4);
27105 else b /= 12.92;
27106
27107 double x = r * 0.4124 + g * 0.3576 + b * 0.1805;
27108 double y = r * 0.2126 + g * 0.7152 + b * 0.0722;
27109 double z = r * 0.0193 + g * 0.1192 + b * 0.9505;
27110
27111 if (x > 0.008856) x = pow(x, 1.0 / 3.0);
27112 else x = (7.787 * x) + (16.0 / 116.0);
27113 if (y > 0.008856) y = pow(y, 1.0 / 3.0);
27114 else y = (7.787 * y) + (16.0 / 116.0);
27115 if (z > 0.008856) z = pow(z, 1.0 / 3.0);
27116 else z = (7.787 * z) + (16.0 / 116.0);
27117
27118 double CIEL = (116 * y) - 16;
27119 double CIEa = 500 * (x - y);
27120 double CIEb = 200 * (y - z);
27121
27122 arr[0] = CIEL;
27123 arr[1] = CIEa;
27124 arr[2] = CIEb;
27125 break;
27126 }
27127 case CSPACE_LCH_CW:
27128 case CSPACE_LCH_CCW:
27129 case CSPACE_LCH:
27130 {
27131 if (r > 0.04045) r = pow(((r + 0.055) / 1.055), 2.4);
27132 else r /= 12.92;
27133 if (g > 0.04045) g = pow(((g + 0.055) / 1.055), 2.4);
27134 else g /= 12.92;
27135 if (b > 0.04045) b = pow(((b + 0.055) / 1.055), 2.4);
27136 else b /= 12.92;
27137
27138 double x = r * 0.4124 + g * 0.3576 + b * 0.1805;
27139 double y = r * 0.2126 + g * 0.7152 + b * 0.0722;
27140 double z = r * 0.0193 + g * 0.1192 + b * 0.9505;
27141
27142 if (x > 0.008856) x = pow(x, 1.0 / 3.0);
27143 else x = (7.787 * x) + (16.0 / 116.0);
27144 if (y > 0.008856) y = pow(y, 1.0 / 3.0);
27145 else y = (7.787 * y) + (16.0 / 116.0);
27146 if (z > 0.008856) z = pow(z, 1.0 / 3.0);
27147 else z = (7.787 * z) + (16.0 / 116.0);
27148
27149 double CIEL = (116 * y) - 16;
27150 double CIEa = 500 * (x - y);
27151 double CIEb = 200 * (y - z);
27152
27153 double h = atan2(CIEb, CIEa);
27154 if (h > 0) h = (h / PI) * 180;
27155 else h = 360 - (abs(h) / PI) * 180;
27156
27157 double CIEC = sqrt(pow(CIEa, 2) + pow(CIEb, 2));
27158
27159 arr[0] = CIEL;
27160 arr[1] = CIEC;
27161 arr[2] = h;
27162 break;
27163 }
27164 }
27165
27166 }
27167
27168 RGB user_paldata::RGBFrom(double arr[], int32_t color_space)
27169 {
27170 double upper = scripting_max_color_val;
27171 double r = 0.0;
27172 double g = 0.0;
27173 double b = 0.0;
27174 switch (color_space)
27175 {
27176 case CSPACE_CMYK:
27177 {
27178 double c = (arr[0] * (1 - arr[3]) + arr[3]);
27179 double m = (arr[1] * (1 - arr[3]) + arr[3]);
27180 double y = (arr[2] * (1 - arr[3]) + arr[3]);
27181
27182 r = vbound((1 - c) * upper, 0.0, upper);
27183 g = vbound((1 - m) * upper, 0.0, upper);
27184 b = vbound((1 - y) * upper, 0.0, upper);
27185 return _RGB(r, g, b);
27186 break;
27187 }
27188 case CSPACE_HSV_CW:
27189 case CSPACE_HSV_CCW:
27190 case CSPACE_HSV:
27191 {
27192 double h = arr[0];
27193 double s = arr[1];
27194 double v = arr[2];
27195
27196 if (s == 0)
27197 {
27198 r = v;
27199 g = v;
27200 b = v;
27201 }
27202 else
27203 {
27204 double var_h = h * 6;
27205 if (var_h >= 6) var_h = 0;
27206 int32_t var_i = floor(var_h);
27207 double var_1 = v * (1 - s);
27208 double var_2 = v * (1 - s * (var_h - var_i));
27209 double var_3 = v * (1 - s * (1 - (var_h - var_i)));
27210
27211 switch (var_i)
27212 {
27213 case 0:
27214 r = v;
27215 g = var_3;
27216 b = var_1;
27217 break;
27218 case 1:
27219 r = var_2;
27220 g = v;
27221 b = var_1;
27222 break;
27223 case 2:
27224 r = var_1;
27225 g = v;
27226 b = var_3;
27227 break;
27228 case 3:
27229 r = var_1;
27230 g = var_2;
27231 b = v;
27232 break;
27233 case 4:
27234 r = var_3;
27235 g = var_1;
27236 b = v;
27237 break;
27238 default:
27239 r = v;
27240 g = var_1;
27241 b = var_2;
27242 }
27243 }
27244
27245 r = vbound(r * upper, 0.0, upper);
27246 g = vbound(g * upper, 0.0, upper);
27247 b = vbound(b * upper, 0.0, upper);
27248
27249 return _RGB(r, g, b);
27250 }
27251 case CSPACE_HSL_CW:
27252 case CSPACE_HSL_CCW:
27253 case CSPACE_HSL:
27254 {
27255 double h = arr[0];
27256 double s = arr[1];
27257 double l = arr[2];
27258
27259 if (s == 0)
27260 {
27261 r = l;
27262 g = l;
27263 b = l;
27264 }
27265 else
27266 {
27267 double var_1;
27268 double var_2;
27269 if (l < 0.5)var_2 = l * (1 + s);
27270 else var_2 = (l + s) - (s * l);
27271
27272 var_1 = 2 * l - var_2;
27273
27274 r = HueToRGB(var_1, var_2, h + (1.0 / 3.0));
27275 g = HueToRGB(var_1, var_2, h);
27276 b = HueToRGB(var_1, var_2, h - (1.0 / 3.0));
27277 }
27278
27279 r = vbound(r * upper, 0.0, upper);
27280 g = vbound(g * upper, 0.0, upper);
27281 b = vbound(b * upper, 0.0, upper);
27282
27283 return _RGB(r, g, b);
27284 }
27285 case CSPACE_LAB:
27286 {
27287 double CIEL = arr[0];
27288 double CIEa = arr[1];
27289 double CIEb = arr[2];
27290
27291 double var_y = (CIEL + 16) / 116.0;
27292 double var_x = CIEa / 500.0 + var_y;
27293 double var_z = var_y - CIEb / 200.0;
27294
27295 if (pow(var_x, 3) > 0.008856) var_x = pow(var_x, 3);
27296 else var_x = (var_x - 16.0 / 116.0) / 7.787;
27297 if (pow(var_y, 3) > 0.008856) var_y = pow(var_y, 3);
27298 else var_y = (var_y - 16.0 / 116.0) / 7.787;
27299 if (pow(var_z, 3) > 0.008856) var_z = pow(var_z, 3);
27300 else var_z = (var_z - 16.0 / 116.0) / 7.787;
27301
27302 r = var_x * 3.2406 + var_y * -1.5372 + var_z * -0.4986;
27303 g = var_x * -0.9689 + var_y * 1.8758 + var_z * 0.0415;
27304 b = var_x * 0.0557 + var_y * -0.2040 + var_z * 1.0570;
27305
27306 if (r > 0.0031308) r = 1.055 * pow(r, (1 / 2.4)) - 0.055;
27307 else r = 12.92 * r;
27308 if (g > 0.0031308) g = 1.055 * pow(g, (1 / 2.4)) - 0.055;
27309 else g = 12.92 * g;
27310 if (b > 0.0031308) b = 1.055 * pow(b, (1 / 2.4)) - 0.055;
27311 else b = 12.92 * b;
27312
27313 r = vbound(r * upper, 0.0, upper);
27314 g = vbound(g * upper, 0.0, upper);
27315 b = vbound(b * upper, 0.0, upper);
27316
27317 return _RGB(r, g, b);
27318 }
27319 case CSPACE_LCH_CW:
27320 case CSPACE_LCH_CCW:
27321 case CSPACE_LCH:
27322 {
27323 double CIEL = arr[0];
27324 double CIEa = cos((arr[2] * PI) / 180.0) * arr[1];
27325 double CIEb = sin((arr[2] * PI) / 180.0) * arr[1];
27326
27327 double var_y = (CIEL + 16) / 116.0;
27328 double var_x = CIEa / 500.0 + var_y;
27329 double var_z = var_y - CIEb / 200.0;
27330
27331 if (pow(var_y, 3) > 0.008856) var_y = pow(var_y, 3);
27332 else var_y = (var_y - 16.0 / 116.0) / 7.787;
27333 if (pow(var_x, 3) > 0.008856) var_x = pow(var_x, 3);
27334 else var_x = (var_x - 16.0 / 116.0) / 7.787;
27335 if (pow(var_z, 3) > 0.008856) var_z = pow(var_z, 3);
27336 else var_z = (var_z - 16.0 / 116.0) / 7.787;
27337
27338 r = var_x * 3.2406 + var_y * -1.5372 + var_z * -0.4986;
27339 g = var_x * -0.9689 + var_y * 1.8758 + var_z * 0.0415;
27340 b = var_x * 0.0557 + var_y * -0.2040 + var_z * 1.0570;
27341
27342 if (r > 0.0031308) r = 1.055 * pow(r, (1 / 2.4)) - 0.055;
27343 else r = 12.92 * r;
27344 if (g > 0.0031308) g = 1.055 * pow(g, (1 / 2.4)) - 0.055;
27345 else g = 12.92 * g;
27346 if (b > 0.0031308) b = 1.055 * pow(b, (1 / 2.4)) - 0.055;
27347 else b = 12.92 * b;
27348
27349 r = vbound(r * upper, 0.0, upper);
27350 g = vbound(g * upper, 0.0, upper);
27351 b = vbound(b * upper, 0.0, upper);
27352
27353 return _RGB(r, g, b);
27354 }
27355 }
27356 return _RGB(0, 0, 0);
27357 }
27358 double user_paldata::HueToRGB(double v1, double v2, double vH)
27359 {
27360 if (vH < 0) vH += 1;
27361 if (vH > 1) vH -= 1;
27362 if ((6 * vH) < 1) return (v1 + (v2 - v1) * 6 * vH);
27363 if ((2 * vH) < 1) return (v2);
27364 if ((3 * vH) < 2) return (v1 + (v2 - v1) * ((2.0 / 3.0) - vH) * 6);
27365 return (v1);
27366 }
27367
27368 double user_paldata::WrapLerp(double a, double b, double t, double min, double max, int32_t direction)
27369 {
27370 double dif = abs(a - b);
27371 double range = abs(max - min);
27372
27373 switch (direction)
27374 {
27375 case 0:
27376 if (dif > range * 0.5)
27377 dif = range - dif;
27378 if (a + dif == b)
27379 direction = 1;
27380 else
27381 direction = -1;
27382 break;
27383 case 1:
27384 if (b < a)
27385 dif = range - dif;
27386 break;
27387 case -1:
27388 if (b > a)
27389 dif = range - dif;
27390 break;
27391 }
27392
27393 double ret = zc::math::Lerp(a, a + dif * direction, t);
27394
27395 if (ret <= min)
27396 ret += range;
27397 else if (ret >= max)
27398 ret -= range;
27399 return ret;
27400 }
27401
27402 //Mixes an entire palette given two paldatas
27403 5231 void user_paldata::mix(user_paldata *pal_start, user_paldata *pal_end, double percent, int32_t color_space, int32_t start_color, int32_t end_color)
27404 {
27405
2/2
✓ Branch 0 taken 184496 times.
✓ Branch 1 taken 5231 times.
189727 for (int32_t q = start_color; q < end_color; ++q)
27406 {
27407
3/4
✓ Branch 0 taken 139696 times.
✓ Branch 1 taken 44800 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 139696 times.
184496 if (get_bit(pal_start->colors_used, q) && get_bit(pal_end->colors_used, q)) {
27408 139696 RGB start = pal_start->colors[q];
27409 139696 RGB end = pal_end->colors[q];
27410 139696 colors[q] = mix_color(start, end, percent, color_space);
27411 139696 set_bit(colors_used, q, true);
27412 139696 }
27413 184496 }
27414 5231 }
27415
27416 53 void item_display_name(const bool setter)
27417 {
27418 53 int32_t ID = ri->idata;
27419
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
53 if(unsigned(ID) >= MAXITEMS)
27420 return;
27421 53 int32_t arrayptr = get_register(sarg1) / 10000;
27422
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
53 if(setter)
27423 {
27424 std::string str;
27425 ArrayH::getString(arrayptr, str, 255);
27426 strcpy(itemsbuf[ID].display_name, str.c_str());
27427 }
27428 else
27429 {
27430
3/6
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 53 times.
✓ Branch 4 taken 53 times.
✗ Branch 5 not taken.
53 if(ArrayH::setArray(arrayptr, string(itemsbuf[ID].display_name)) == SH::_Overflow)
27431 Z_scripterrlog("Array supplied to 'itemdata->GetDisplayName()' not large enough\n");
27432 }
27433 53 }
27434 void item_shown_name()
27435 {
27436 int32_t ID = ri->idata;
27437 if(unsigned(ID) >= MAXITEMS)
27438 return;
27439 int32_t arrayptr = get_register(sarg1) / 10000;
27440 if(ArrayH::setArray(arrayptr, itemsbuf[ID].get_name()) == SH::_Overflow)
27441 Z_scripterrlog("Array supplied to 'itemdata->GetShownName()' not large enough\n");
27442 }
27443
27444 void FFScript::do_getDMapData_dmapname(const bool v)
27445 {
27446 int32_t ID = ri->dmapsref;
27447 int32_t arrayptr = get_register(sarg1) / 10000;
27448
27449 if(BC::checkDMapID(ID) != SH::_NoError)
27450 return;
27451
27452 if(ArrayH::setArray(arrayptr, string(DMaps[ID].name)) == SH::_Overflow)
27453 Z_scripterrlog("Array supplied to 'dmapdata->GetName()' not large enough\n");
27454 }
27455
27456 void FFScript::do_setDMapData_dmapname(const bool v)
27457 {
27458 int32_t ID = ri->dmapsref;
27459 int32_t arrayptr = get_register(sarg1) / 10000;
27460
27461 string filename_str;
27462
27463 if(BC::checkDMapID(ID) != SH::_NoError)
27464 return;
27465
27466
27467 ArrayH::getString(arrayptr, filename_str, 22);
27468 strncpy(DMaps[ID].name, filename_str.c_str(), 21);
27469 DMaps[ID].name[20]='\0';
27470 }
27471
27472 void FFScript::do_getDMapData_dmaptitle(const bool v)
27473 {
27474 int32_t ID = ri->dmapsref;
27475 int32_t arrayptr = get_register(sarg1) / 10000;
27476
27477 if(BC::checkDMapID(ID) != SH::_NoError)
27478 return;
27479
27480 if (!get_qr(qr_OLD_DMAP_INTRO_STRINGS))
27481 {
27482 ArrayManager am(arrayptr);
27483 am.resize(DMaps[ID].title.size() + 1);
27484 }
27485 if(ArrayH::setArray(arrayptr, string(DMaps[ID].title)) == SH::_Overflow)
27486 Z_scripterrlog("Array supplied to 'dmapdata->GetTitle()' not large enough\n");
27487 }
27488
27489 void FFScript::do_setDMapData_dmaptitle(const bool v)
27490 {
27491 int32_t ID = ri->dmapsref;
27492 int32_t arrayptr = get_register(sarg1) / 10000;
27493 string filename_str;
27494
27495 if(BC::checkDMapID(ID) != SH::_NoError)
27496 return;
27497
27498 if (get_qr(qr_OLD_DMAP_INTRO_STRINGS))
27499 {
27500 char namestr[21];
27501 ArrayH::getString(arrayptr, filename_str, 21);
27502 strncpy(namestr, filename_str.c_str(), 20);
27503 namestr[20] = '\0';
27504 DMaps[ID].title.assign(namestr);
27505 }
27506 else
27507 {
27508 ArrayH::getString(arrayptr, filename_str, ArrayH::getSize(arrayptr));
27509 DMaps[ID].title = filename_str;
27510 }
27511 }
27512
27513 void FFScript::do_getDMapData_dmapintro(const bool v)
27514 {
27515 int32_t ID = ri->dmapsref;
27516 int32_t arrayptr = get_register(sarg1) / 10000;
27517
27518 if(BC::checkDMapID(ID) != SH::_NoError)
27519 return;
27520
27521 if(ArrayH::setArray(arrayptr, string(DMaps[ID].intro)) == SH::_Overflow)
27522 Z_scripterrlog("Array supplied to 'dmapdata->GetIntro()' not large enough\n");
27523 }
27524
27525 void FFScript::do_setDMapData_dmapintro(const bool v)
27526 {
27527 int32_t ID = ri->dmapsref;
27528 int32_t arrayptr = get_register(sarg1) / 10000;
27529 string filename_str;
27530
27531 if(BC::checkDMapID(ID) != SH::_NoError)
27532 return;
27533
27534
27535 ArrayH::getString(arrayptr, filename_str, 73);
27536 strncpy(DMaps[ID].intro, filename_str.c_str(), 72);
27537 DMaps[ID].intro[72]='\0';
27538 }
27539
27540 void FFScript::do_getDMapData_music(const bool v)
27541 {
27542 int32_t ID = ri->dmapsref;
27543 int32_t arrayptr = get_register(sarg1) / 10000;
27544
27545 if(BC::checkDMapID(ID) != SH::_NoError)
27546 return;
27547
27548 if(ArrayH::setArray(arrayptr, string(DMaps[ID].tmusic)) == SH::_Overflow)
27549 Z_scripterrlog("Array supplied to 'dmapdata->GetMusic()' not large enough\n");
27550 }
27551
27552 void FFScript::do_setDMapData_music(const bool v)
27553 {
27554 int32_t ID = ri->dmapsref;
27555 int32_t arrayptr = get_register(sarg1) / 10000;
27556 string filename_str;
27557
27558 if(BC::checkDMapID(ID) != SH::_NoError)
27559 return;
27560
27561
27562 ArrayH::getString(arrayptr, filename_str, 56);
27563 strncpy(DMaps[ID].tmusic, filename_str.c_str(), 55);
27564 DMaps[ID].tmusic[55]='\0';
27565 }
27566
27567 6365 void FFScript::do_loadnpcdata(const bool v)
27568 {
27569 6365 int32_t ID = SH::get_arg(sarg1, v) / 10000;
27570
27571
2/4
✓ Branch 0 taken 6365 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6365 times.
6365 if ( ID < 1 || ID > (MAXGUYS-1) )
27572 {
27573 Z_scripterrlog("Invalid NPC ID passed to Game->LoadNPCData: %d\n", ID);
27574 ri->npcdataref = MAX_DWORD;
27575 }
27576
27577 6365 else ri->npcdataref = ID;
27578 6365 }
27579 24 void FFScript::do_loadmessagedata(const bool v)
27580 {
27581 24 int32_t ID = SH::get_arg(sarg1, v) / 10000;
27582
27583
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
24 if ( ID < 1 || ID > (msg_count-1) )
27584 {
27585 Z_scripterrlog("Invalid Message ID passed to Game->LoadMessageData: %d\n", ID);
27586 ri->zmsgref = MAX_DWORD;
27587 }
27588
27589 24 else ri->zmsgref = ID;
27590 24 }
27591 //same syntax as loadmessage data
27592 //the input is an array
27593 24 void FFScript::do_messagedata_setstring(const bool v)
27594 {
27595 24 int32_t arrayptr = get_register(sarg1) / 10000;
27596 24 int32_t ID = ri->zmsgref;
27597
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if(BC::checkMessage(ID) != SH::_NoError)
27598 return;
27599
27600 24 std::string s;
27601
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ArrayH::getString(arrayptr, s, MSG_NEW_SIZE);
27602
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 MsgStrings[ID].setFromLegacyEncoding(s);
27603 24 }
27604 void FFScript::do_messagedata_getstring(const bool v)
27605 {
27606 int32_t ID = ri->zmsgref;
27607 int32_t arrayptr = get_register(sarg1) / 10000;
27608
27609 if(BC::checkMessage(ID) != SH::_NoError)
27610 return;
27611
27612 if(ArrayH::setArray(arrayptr, MsgStrings[ID].s) == SH::_Overflow)
27613 Z_scripterrlog("Array supplied to 'messagedata->Get()' not large enough\n");
27614 }
27615
27616 432438 void FFScript::do_loadcombodata(const bool v)
27617 {
27618 432438 int32_t ID = SH::get_arg(sarg1, v) / 10000;
27619
27620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 432438 times.
432438 if ( (unsigned)ID > (MAXCOMBOS-1) )
27621 {
27622 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
27623 ri->combosref = 0;
27624 }
27625
27626 432438 else ri->combosref = ID;
27627 432438 }
27628
27629 3209685 void FFScript::do_loadmapdata_tempscr(const bool v)
27630 {
27631 3209685 int32_t layer = SH::get_arg(sarg1, v) / 10000;
27632
27633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3209685 times.
3209685 if (BC::checkBounds(layer, 0, 6) != SH::_NoError)
27634 {
27635 ri->mapsref = 0;
27636 set_register(sarg1, ri->mapsref);
27637 return;
27638 }
27639
27640 3209685 ri->mapsref = create_mapdata_temp_ref(mapdata_type::TemporaryCurrentRegion, cur_screen, layer);
27641 3209685 set_register(sarg1, ri->mapsref);
27642 3209685 }
27643
27644 void FFScript::do_loadmapdata_tempscr2(const bool v)
27645 {
27646 int32_t layer = SH::get_arg(sarg1, v) / 10000;
27647 int32_t screen = SH::get_arg(sarg2, v) / 10000;
27648
27649 if (BC::checkBounds(layer, 0, 6) != SH::_NoError)
27650 {
27651 ri->mapsref = 0;
27652 set_register(sarg1, ri->mapsref);
27653 return;
27654 }
27655
27656 if (!is_in_current_region(screen))
27657 {
27658 scripting_log_error_with_context("Must use a screen in the current region. got: {}", screen);
27659 ri->mapsref = 0;
27660 set_register(sarg1, ri->mapsref);
27661 return;
27662 }
27663
27664 ri->mapsref = create_mapdata_temp_ref(mapdata_type::TemporaryCurrentScreen, screen, layer);
27665 set_register(sarg1, ri->mapsref);
27666 }
27667
27668 static void do_loadtmpscrforcombopos(const bool v)
27669 {
27670 int32_t layer = SH::get_arg(sarg1, v) / 10000;
27671 rpos_t rpos = (rpos_t)(SH::get_arg(sarg2, v) / 10000);
27672
27673 if (BC::checkBoundsRpos(rpos, (rpos_t)0, region_max_rpos) != SH::_NoError)
27674 {
27675 ri->mapsref = 0;
27676 set_register(sarg1, ri->mapsref);
27677 return;
27678 }
27679 if (BC::checkBounds(layer, 0, 6) != SH::_NoError)
27680 {
27681 ri->mapsref = 0;
27682 set_register(sarg1, ri->mapsref);
27683 return;
27684 }
27685
27686 set_register(sarg1, create_mapdata_temp_ref(mapdata_type::TemporaryCurrentScreen, get_screen_for_rpos(rpos), layer));
27687 }
27688
27689 177544 void FFScript::do_loadmapdata_scrollscr(const bool v)
27690 {
27691 177544 int32_t layer = SH::get_arg(sarg1, v) / 10000;
27692
27693
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 177544 times.
177544 if (BC::checkBounds(layer, 0, 6) != SH::_NoError)
27694 {
27695 ri->mapsref = 0;
27696 set_register(sarg1, ri->mapsref);
27697 return;
27698 }
27699
27700 177544 ri->mapsref = create_mapdata_temp_ref(mapdata_type::TemporaryScrollingRegion, scrolling_hero_screen, layer);
27701 177544 set_register(sarg1, ri->mapsref);
27702 177544 }
27703
27704 void FFScript::do_loadmapdata_scrollscr2(const bool v)
27705 {
27706 int32_t layer = SH::get_arg(sarg1, v) / 10000;
27707 int32_t screen = SH::get_arg(sarg2, v) / 10000;
27708
27709 if (BC::checkBounds(layer, 0, 6) != SH::_NoError)
27710 {
27711 ri->mapsref = 0;
27712 set_register(sarg1, ri->mapsref);
27713 return;
27714 }
27715
27716 if (!is_in_scrolling_region(screen))
27717 {
27718 scripting_log_error_with_context("Must use a screen in the current scrolling region. got: {}", screen);
27719 ri->mapsref = 0;
27720 set_register(sarg1, ri->mapsref);
27721 return;
27722 }
27723
27724 ri->mapsref = create_mapdata_temp_ref(mapdata_type::TemporaryScrollingScreen, screen, layer);
27725 set_register(sarg1, ri->mapsref);
27726 }
27727
27728 void FFScript::do_loadshopdata(const bool v)
27729 {
27730 int32_t ID = SH::get_arg(sarg1, v) / 10000;
27731
27732 if ( (unsigned)ID > 255 )
27733 {
27734 Z_scripterrlog("Invalid Shop ID passed to Game->LoadShopData: %d\n", ID);
27735 ri->shopsref = 0;
27736 }
27737 else ri->shopsref = ID;
27738 }
27739
27740
27741 void FFScript::do_loadinfoshopdata(const bool v)
27742 {
27743 int32_t ID = SH::get_arg(sarg1, v) / 10000;
27744
27745 if ( (unsigned)ID > 255 )
27746 {
27747 Z_scripterrlog("Invalid Shop ID passed to Game->LoadShopData: %d\n", ID);
27748 ri->shopsref = 0;
27749 }
27750 else ri->shopsref = ID+NUMSHOPS;
27751 }
27752
27753 16 void FFScript::do_loadspritedata(const bool v)
27754 {
27755 16 int32_t ID = SH::get_arg(sarg1, v) / 10000;
27756
27757
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if ( (unsigned)ID > (MAXWPNS-1) )
27758 {
27759 Z_scripterrlog("Invalid Sprite ID passed to Game->LoadSpriteData: %d\n", ID);
27760 ri->spritedataref = 0;
27761 }
27762
27763 16 else ri->spritedataref = ID;
27764 16 }
27765
27766 8 void FFScript::do_loadbitmapid(const bool v)
27767 {
27768 8 int32_t ID = SH::get_arg(sarg1, v) / 10000;
27769
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 switch(ID)
27770 {
27771 case rtSCREEN:
27772 case rtBMP0:
27773 case rtBMP1:
27774 case rtBMP2:
27775 case rtBMP3:
27776 case rtBMP4:
27777 case rtBMP5:
27778 case rtBMP6:
27779 8 ri->bitmapref = ID+10; break;
27780 default:
27781 {
27782 Z_scripterrlog("Invalid Bitmap ID passed to Game->Load BitmapID: %d\n", ID);
27783 ri->bitmapref = 0; break;
27784 }
27785 }
27786 8 }
27787
27788 87667 void do_createlweapon(const bool v)
27789 {
27790 87667 const int32_t ID = SH::get_arg(sarg1, v) / 10000;
27791
27792
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 87667 times.
87667 if(BC::checkWeaponID(ID) != SH::_NoError)
27793 return;
27794
27795
1/2
✓ Branch 0 taken 87667 times.
✗ Branch 1 not taken.
87667 if ( Lwpns.has_space() )
27796 {
27797 87667 (void)Lwpns.add
27798 (
27799
1/2
✓ Branch 0 taken 87667 times.
✗ Branch 1 not taken.
175334 new weapon
27800 (
27801
1/2
✓ Branch 0 taken 87667 times.
✗ Branch 1 not taken.
87667 (zfix)0, /*X*/
27802
1/2
✓ Branch 0 taken 87667 times.
✗ Branch 1 not taken.
87667 (zfix)0, /*Y*/
27803
1/2
✓ Branch 0 taken 87667 times.
✗ Branch 1 not taken.
87667 (zfix)0, /*Z*/
27804 87667 ID, /*id*/
27805 0, /*type*/
27806 0, /*power*/
27807 0, /*dir*/
27808 -1, /*Parentid*/
27809
1/2
✓ Branch 0 taken 87667 times.
✗ Branch 1 not taken.
87667 Hero.getUID(), /*prntid*/
27810 false, /*isdummy*/
27811 1, /*script_gen*/
27812 1, /*islwpn*/
27813 87667 (ID==wWind?1:0) /*special*/
27814 )
27815 );
27816 87667 ri->lwpn = Lwpns.spr(Lwpns.Count() - 1)->getUID();
27817 87667 weapon *w = (weapon*)Lwpns.spr(Lwpns.Count()-1); //last created
27818 87667 w->screen_spawned = ri->screenref;
27819 87667 w->ScriptGenerated = 1;
27820 87667 w->isLWeapon = 1;
27821
1/2
✓ Branch 0 taken 87667 times.
✗ Branch 1 not taken.
87667 if(ID == wWind) w->specialinfo = 1;
27822 87667 Z_eventlog("Script created lweapon %ld with UID = %ld\n", ID, ri->lwpn);
27823 87667 }
27824 else
27825 {
27826 ri->lwpn = 0; // Now NULL
27827 Z_scripterrlog("Couldn't create lweapon %ld, screen lweapon limit reached\n", ID);
27828 }
27829 87667 }
27830
27831 209493 void do_createeweapon(const bool v)
27832 {
27833 209493 const int32_t ID = SH::get_arg(sarg1, v) / 10000;
27834
27835
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 209493 times.
209493 if(BC::checkWeaponID(ID) != SH::_NoError)
27836 return;
27837
27838
1/2
✓ Branch 0 taken 209493 times.
✗ Branch 1 not taken.
209493 if ( Ewpns.has_space() )
27839 {
27840 209493 addEwpn(0, 0, 0, ID, 0, 0, 0, -1,1); //Param 9 marks it as script-generated.
27841
4/6
✓ Branch 0 taken 150748 times.
✓ Branch 1 taken 58745 times.
✓ Branch 2 taken 150748 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 150748 times.
✗ Branch 5 not taken.
209493 if( ID > wEnemyWeapons || ( ID >= wScript1 && ID <= wScript10) )
27842 {
27843 209493 weapon *w = (weapon*)Ewpns.spr(Ewpns.Count()-1); //last created
27844 209493 w->screen_spawned = ri->screenref;
27845 209493 w->ScriptGenerated = 1;
27846 209493 w->isLWeapon = 0;
27847 209493 ri->ewpn = Ewpns.spr(Ewpns.Count() - 1)->getUID();
27848 209493 Z_eventlog("Script created eweapon %ld with UID = %ld\n", ID, ri->ewpn);
27849 209493 }
27850 else
27851 {
27852 Z_scripterrlog("Couldn't create eweapon %ld: Invalid ID/Type (%d) specified.\n", ID);
27853 return;
27854 }
27855 209493 }
27856 else
27857 {
27858 ri->ewpn = 0;
27859 Z_scripterrlog("Couldn't create eweapon %ld, screen eweapon limit reached\n", ID);
27860 }
27861 209493 }
27862
27863 22443 void do_createitem(const bool v)
27864 {
27865 22443 const int32_t ID = SH::get_arg(sarg1, v) / 10000;
27866
27867
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22443 times.
22443 if(BC::checkItemID(ID) != SH::_NoError)
27868 return;
27869
27870
1/2
✓ Branch 0 taken 22443 times.
✗ Branch 1 not taken.
22443 if ( items.has_space() )
27871 {
27872 22443 additem(0, (get_qr(qr_NOITEMOFFSET) ? 1: 0), ID, ipBIGRANGE);
27873 22443 sprite* item = items.spr(items.Count() - 1);
27874 22443 item->screen_spawned = ri->screenref;
27875 22443 ri->itemref = item->getUID();
27876 22443 Z_eventlog("Script created item \"%s\" with UID = %ld\n", item_string[ID], ri->itemref);
27877 22443 }
27878 else
27879 {
27880 ri->itemref = 0;
27881 Z_scripterrlog("Couldn't create item \"%s\", screen item limit reached\n", item_string[ID]);
27882 }
27883 22443 }
27884
27885 3530 void do_createnpc(const bool v)
27886 {
27887 3530 const int32_t ID = SH::get_arg(sarg1, v) / 10000;
27888
27889
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3530 times.
3530 if(BC::checkGuyID(ID) != SH::_NoError)
27890 return;
27891
27892 //If we make a segmented enemy there'll be more than one sprite created
27893 3530 word numcreated = addenemy(ri->screenref, 0, 0, ID, -10);
27894
27895
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3530 times.
3530 if(numcreated == 0)
27896 {
27897 //ri->guyref = MAX_DWORD;
27898 ri->guyref = 0;
27899 Z_scripterrlog("Couldn't create NPC \"%s\", screen NPC limit reached\n", guy_string[ID]);
27900 }
27901 else
27902 {
27903 3530 word index = guys.Count() - numcreated; //Get the main enemy, not a segment
27904 3530 ri->guyref = guys.spr(index)->getUID();
27905
27906
2/2
✓ Branch 0 taken 3566 times.
✓ Branch 1 taken 3530 times.
7096 for(; index<guys.Count(); index++)
27907 3566 ((enemy*)guys.spr(index))->script_spawned=true;
27908
27909 3530 Z_eventlog("Script created NPC \"%s\" with UID = %ld\n", guy_string[ID], ri->guyref);
27910 }
27911 3530 }
27912
27913 ///----------------------------------------------------------------------------------------------------//
27914 //Drawing & Sound
27915
27916 1117 void do_message(const bool v)
27917 {
27918 1117 const int32_t ID = SH::get_arg(sarg1, v) / 10000;
27919
27920
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1117 times.
1117 if(BC::checkMessage(ID) != SH::_NoError)
27921 return;
27922
27923
2/2
✓ Branch 0 taken 302 times.
✓ Branch 1 taken 815 times.
1117 if(ID == 0)
27924 {
27925 302 dismissmsg();
27926 302 msgfont = get_zc_font(font_zfont);
27927 302 blockpath = false;
27928 302 Hero.finishedmsg();
27929 302 }
27930 else
27931 815 donewmsg(get_scr(ri->screenref), ID);
27932 1117 }
27933
27934 45275698 INLINE void set_drawing_command_args(const int32_t j, const word numargs)
27935 {
27936
1/2
✓ Branch 0 taken 45275698 times.
✗ Branch 1 not taken.
45275698 assert(numargs <= DRAWCMD_MAX_ARG_COUNT);
27937
2/2
✓ Branch 0 taken 368858404 times.
✓ Branch 1 taken 45275698 times.
414134102 for(int32_t k = 1; k <= numargs; k++)
27938 368858404 script_drawing_commands[j][k] = SH::read_stack(ri->sp + (numargs - k));
27939 45275698 }
27940
27941 53710506 INLINE void set_user_bitmap_command_args(const int32_t j, const word numargs)
27942 {
27943
1/2
✓ Branch 0 taken 53710506 times.
✗ Branch 1 not taken.
53710506 assert(numargs <= DRAWCMD_MAX_ARG_COUNT);
27944 //ri->bitmapref = SH::read_stack(ri->sp+numargs);
27945
2/2
✓ Branch 0 taken 326054646 times.
✓ Branch 1 taken 53710506 times.
379765152 for(int32_t k = 1; k <= numargs; k++)
27946 326054646 script_drawing_commands[j][k] = SH::read_stack(ri->sp + (numargs - k));
27947 53710506 }
27948
27949 98985124 static DrawOrigin get_draw_origin_for_screen_draw_command()
27950 {
27951 98985124 DrawOrigin draw_origin = ri->screen_draw_origin;
27952
27953
2/2
✓ Branch 0 taken 121364 times.
✓ Branch 1 taken 98863760 times.
98985124 if (draw_origin == DrawOrigin::Default)
27954 {
27955
4/4
✓ Branch 0 taken 8256 times.
✓ Branch 1 taken 98855504 times.
✓ Branch 2 taken 94943409 times.
✓ Branch 3 taken 3912095 times.
98863760 bool in_scrolling_region = is_in_scrolling_region() || (screenscrolling && scrolling_region.screen_count > 1);
27956 98863760 draw_origin = in_scrolling_region ? DrawOrigin::Region : DrawOrigin::PlayingField;
27957 98863760 }
27958
2/2
✓ Branch 0 taken 46076 times.
✓ Branch 1 taken 98939048 times.
98985124 if (draw_origin == DrawOrigin::Region)
27959 {
27960
2/2
✓ Branch 0 taken 38992 times.
✓ Branch 1 taken 7084 times.
46076 if (scrolling_using_new_region_coords)
27961 7084 draw_origin = DrawOrigin::RegionScrollingNew;
27962 46076 }
27963
2/2
✓ Branch 0 taken 1484 times.
✓ Branch 1 taken 98937564 times.
98939048 else if (draw_origin == DrawOrigin::RegionScrollingOld)
27964 {
27965 1484 draw_origin = DrawOrigin::Region;
27966 1484 }
27967
2/2
✓ Branch 0 taken 98936576 times.
✓ Branch 1 taken 988 times.
98937564 else if (draw_origin == DrawOrigin::RegionScrollingNew)
27968 {
27969
1/2
✓ Branch 0 taken 988 times.
✗ Branch 1 not taken.
988 if (!screenscrolling)
27970 draw_origin = DrawOrigin::Region;
27971 988 }
27972
27973 98985124 return draw_origin;
27974 }
27975
27976 1440 static DrawOrigin get_draw_origin_for_bitmap_draw_command()
27977 {
27978 1440 return DrawOrigin::Screen;
27979 }
27980
27981 98986564 static std::pair<DrawOrigin, int> get_draw_origin_for_draw_command(bool is_screen_draw, int scripting_bitmap_id)
27982 {
27983
2/2
✓ Branch 0 taken 98984764 times.
✓ Branch 1 taken 1800 times.
98986564 if (get_qr(qr_BROKEN_SCRIPTS_BITMAP_DRAW_ORIGIN))
27984 98984764 return {get_draw_origin_for_screen_draw_command(), ri->screen_draw_origin_target};
27985
27986 1800 auto [bitmap_id, _] = resolveScriptingBitmapId(scripting_bitmap_id);
27987
27988
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1800 times.
1800 if (FFCore.doesResolveToDeprecatedSystemBitmap(bitmap_id))
27989 return {DrawOrigin::Screen, 0};
27990
27991
2/2
✓ Branch 0 taken 360 times.
✓ Branch 1 taken 1440 times.
1800 if (FFCore.doesResolveToScreenBitmap(bitmap_id))
27992 360 return {get_draw_origin_for_screen_draw_command(), ri->screen_draw_origin_target};
27993
27994
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1440 times.
1440 if (!is_screen_draw)
27995 1440 return {get_draw_origin_for_bitmap_draw_command(), 0};
27996
27997 return {DrawOrigin::Screen, 0};
27998 98986564 }
27999
28000 98986204 static void do_drawing_command(int32_t script_command, bool is_screen_draw)
28001 {
28002
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 98986204 times.
98986204 if (FFCore.skipscriptdraws)
28003 return;
28004
28005 98986204 int32_t j = script_drawing_commands.GetNext();
28006
1/2
✓ Branch 0 taken 98986204 times.
✗ Branch 1 not taken.
98986204 if(j == -1) //out of drawing command space
28007 {
28008 Z_scripterrlog("Max draw primitive limit reached\n");
28009 return;
28010 }
28011
28012 98986204 script_drawing_commands[j] = {};
28013 98986204 script_drawing_commands[j][0] = script_command;
28014 98986204 script_drawing_commands[j][DRAWCMD_CURRENT_TARGET] = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
28015
28016
39/81
✓ Branch 0 taken 2428096 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1096118 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 383247 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2698101 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 900326 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 49606 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 321769 times.
✓ Branch 13 taken 2790 times.
✓ Branch 14 taken 26528 times.
✓ Branch 15 taken 148823 times.
✓ Branch 16 taken 144 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 824 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 167318 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 1173 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✓ Branch 29 taken 19821648 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 906 times.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✓ Branch 34 taken 2051 times.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 37 taken 7323 times.
✗ Branch 38 not taken.
✓ Branch 39 taken 1850 times.
✓ Branch 40 taken 2356839 times.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✓ Branch 45 taken 1080 times.
✓ Branch 46 taken 1527166 times.
✓ Branch 47 taken 5152881 times.
✓ Branch 48 taken 21691969 times.
✓ Branch 49 taken 963845 times.
✓ Branch 50 taken 148476 times.
✗ Branch 51 not taken.
✓ Branch 52 taken 9270 times.
✗ Branch 53 not taken.
✓ Branch 54 taken 4137125 times.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✓ Branch 57 taken 1568537 times.
✓ Branch 58 taken 161166 times.
✓ Branch 59 taken 7971 times.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✓ Branch 64 taken 502 times.
✓ Branch 65 taken 80910 times.
✓ Branch 66 taken 59561 times.
✓ Branch 67 taken 32636464 times.
✗ Branch 68 not taken.
✓ Branch 69 taken 865 times.
✓ Branch 70 taken 45504 times.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✓ Branch 74 taken 264103 times.
✓ Branch 75 taken 113329 times.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
98986204 switch(script_command)
28017 {
28018 case RECTR:
28019 2428096 set_drawing_command_args(j, 12);
28020 2428096 break;
28021
28022 case FRAMER:
28023 set_drawing_command_args(j, 9);
28024 break;
28025
28026 case CIRCLER:
28027 1096118 set_drawing_command_args(j, 11);
28028 1096118 break;
28029
28030 case ARCR:
28031 set_drawing_command_args(j, 14);
28032 break;
28033
28034 case ELLIPSER:
28035 1850 set_drawing_command_args(j, 12);
28036 1850 break;
28037
28038 case LINER:
28039 2356839 set_drawing_command_args(j, 11);
28040 2356839 break;
28041
28042 case PUTPIXELR:
28043 383247 set_drawing_command_args(j, 8);
28044 383247 break;
28045
28046 case PIXELARRAYR:
28047 {
28048 set_drawing_command_args(j, 5);
28049 std::vector<int32_t> *v = script_drawing_commands.GetVector();
28050
28051 int32_t arrayptr = script_drawing_commands[j][2]/10000;
28052 if ( !arrayptr ) //Don't crash because of vector size.
28053 {
28054 Z_scripterrlog("Invalid array pointer %d passed to Screen->PutPixels(). Aborting.", arrayptr);
28055 break;
28056 }
28057 int32_t sz = ArrayH::getSize(arrayptr);
28058 if(!sz)
28059 {
28060 script_drawing_commands.PopLast();
28061 return;
28062 }
28063 v->resize(sz, 0);
28064 int32_t* pos = &v->at(0);
28065
28066 ArrayH::getValues(script_drawing_commands[j][2] / 10000, pos, sz);
28067 script_drawing_commands[j].SetVector(v);
28068 break;
28069 }
28070
28071 case TILEARRAYR:
28072 {
28073 set_drawing_command_args(j, 2);
28074 std::vector<int32_t> *v = script_drawing_commands.GetVector();
28075
28076 int32_t arrayptr = script_drawing_commands[j][2]/10000;
28077 if ( !arrayptr ) //Don't crash because of vector size.
28078 {
28079 Z_scripterrlog("Invalid array pointer %d passed to Screen->DrawTiles(). Aborting.", arrayptr);
28080 break;
28081 }
28082 int32_t sz = ArrayH::getSize(arrayptr);
28083 if(!sz)
28084 {
28085 script_drawing_commands.PopLast();
28086 return;
28087 }
28088 v->resize(sz, 0);
28089 int32_t* pos = &v->at(0);
28090
28091 ArrayH::getValues(script_drawing_commands[j][2] / 10000, pos, sz);
28092 script_drawing_commands[j].SetVector(v);
28093 break;
28094 }
28095
28096 case LINESARRAY:
28097 {
28098 set_drawing_command_args(j, 2);
28099 std::vector<int32_t> *v = script_drawing_commands.GetVector();
28100
28101 int32_t arrayptr = script_drawing_commands[j][2]/10000;
28102 if ( !arrayptr ) //Don't crash because of vector size.
28103 {
28104 Z_scripterrlog("Invalid array pointer %d passed to Screen->Lines(). Aborting.", arrayptr);
28105 break;
28106 }
28107 int32_t sz = ArrayH::getSize(arrayptr);
28108 if(!sz)
28109 {
28110 script_drawing_commands.PopLast();
28111 return;
28112 }
28113 v->resize(sz, 0);
28114 int32_t* pos = &v->at(0);
28115
28116 ArrayH::getValues(script_drawing_commands[j][2] / 10000, pos, sz);
28117 script_drawing_commands[j].SetVector(v);
28118 break;
28119 }
28120
28121 case COMBOARRAYR:
28122 {
28123 set_drawing_command_args(j, 2);
28124 std::vector<int32_t> *v = script_drawing_commands.GetVector();
28125 int32_t arrayptr = script_drawing_commands[j][2]/10000;
28126 if ( !arrayptr ) //Don't crash because of vector size.
28127 {
28128 Z_scripterrlog("Invalid array pointer %d passed to Screen->DrawCombos(). Aborting.", arrayptr);
28129 break;
28130 }
28131 int32_t sz = ArrayH::getSize(arrayptr);
28132 if(!sz)
28133 {
28134 script_drawing_commands.PopLast();
28135 return;
28136 }
28137 v->resize(sz, 0);
28138 int32_t* pos = &v->at(0);
28139
28140 ArrayH::getValues(script_drawing_commands[j][2] / 10000, pos, sz);
28141 script_drawing_commands[j].SetVector(v);
28142 break;
28143 }
28144 case POLYGONR:
28145 {
28146 1080 set_drawing_command_args(j, 5);
28147
28148 1080 int32_t arrayptr = script_drawing_commands[j][3]/10000;
28149
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
1080 if ( !arrayptr ) //Don't crash because of vector size.
28150 {
28151 Z_scripterrlog("Invalid array pointer %d passed to Screen->Polygon(). Aborting.", arrayptr);
28152 break;
28153 }
28154 1080 int32_t sz = ArrayH::getSize(arrayptr);
28155
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
1080 if(!sz)
28156 {
28157 script_drawing_commands.PopLast();
28158 return;
28159 }
28160
28161 1080 std::vector<int32_t> *v = script_drawing_commands.GetVector();
28162 1080 v->resize(sz, 0);
28163
28164 1080 int32_t* pos = &v->at(0);
28165
28166
28167 1080 ArrayH::getValues(script_drawing_commands[j][3] / 10000, pos, sz);
28168 1080 script_drawing_commands[j].SetVector(v);
28169 }
28170 1080 break;
28171
28172 case DRAWTILER:
28173 1527166 set_drawing_command_args(j, 15);
28174 1527166 break;
28175
28176 case DRAWTILECLOAKEDR:
28177 set_drawing_command_args(j, 7);
28178 break;
28179
28180 case DRAWCOMBOR:
28181 2698101 set_drawing_command_args(j, 16);
28182 2698101 break;
28183
28184 case DRAWCOMBOCLOAKEDR:
28185 set_drawing_command_args(j, 7);
28186 break;
28187
28188 case FASTTILER:
28189 5152881 set_drawing_command_args(j, 6);
28190 5152881 break;
28191
28192 case FASTCOMBOR:
28193 21691969 set_drawing_command_args(j, 6);
28194 21691969 break;
28195
28196 case DRAWCHARR:
28197 963845 set_drawing_command_args(j, 10);
28198 963845 break;
28199
28200 case DRAWINTR:
28201 148476 set_drawing_command_args(j, 11);
28202 148476 break;
28203
28204 case SPLINER:
28205 set_drawing_command_args(j, 11);
28206 break;
28207
28208 case QUADR:
28209 9270 set_drawing_command_args(j, 15);
28210 9270 break;
28211
28212 case TRIANGLER:
28213 set_drawing_command_args(j, 13);
28214 break;
28215
28216 case BITMAPR:
28217 900326 set_drawing_command_args(j, 12);
28218 900326 break;
28219
28220 case BITMAPEXR:
28221 set_drawing_command_args(j, 16);
28222 break;
28223
28224 case DRAWLAYERR:
28225 4137125 set_drawing_command_args(j, 8);
28226 4137125 break;
28227
28228 case DRAWSCREENR:
28229 49606 set_drawing_command_args(j, 6);
28230 49606 break;
28231
28232 case QUAD3DR:
28233 {
28234 set_drawing_command_args(j, 8);
28235 int32_t arrayptr = script_drawing_commands[j][2]/10000;
28236 int32_t sz = ArrayH::getSize(arrayptr);
28237 arrayptr = script_drawing_commands[j][3]/10000;
28238 sz += ArrayH::getSize(arrayptr);
28239 arrayptr = script_drawing_commands[j][4]/10000;
28240 sz += ArrayH::getSize(arrayptr);
28241 arrayptr = script_drawing_commands[j][5]/10000;
28242 sz += ArrayH::getSize(arrayptr);
28243 if(sz < 25)
28244 {
28245 script_drawing_commands.PopLast();
28246 return;
28247 }
28248 std::vector<int32_t> *v = script_drawing_commands.GetVector();
28249 v->resize(sz, 0);
28250
28251 int32_t* pos = &v->at(0);
28252 int32_t* uv = &v->at(12);
28253 int32_t* col = &v->at(20);
28254 int32_t* size = &v->at(24);
28255
28256 ArrayH::getValues((script_drawing_commands[j][2] / 10000), pos, 12);
28257 ArrayH::getValues((script_drawing_commands[j][3] / 10000), uv, 8);
28258 ArrayH::getValues((script_drawing_commands[j][4] / 10000), col, 4);
28259 //FFCore.getValues2(script_drawing_commands[j][5] / 10000, size, 2);
28260 ArrayH::getValues((script_drawing_commands[j][5] / 10000), size, 2);
28261
28262 script_drawing_commands[j].SetVector(v);
28263 }
28264 break;
28265
28266 case TRIANGLE3DR:
28267 {
28268 set_drawing_command_args(j, 8);
28269
28270 int32_t arrayptr = script_drawing_commands[j][2]/10000;
28271 int32_t sz = ArrayH::getSize(arrayptr);
28272 arrayptr = script_drawing_commands[j][3]/10000;
28273 sz += ArrayH::getSize(arrayptr);
28274 arrayptr = script_drawing_commands[j][4]/10000;
28275 sz += ArrayH::getSize(arrayptr);
28276 arrayptr = script_drawing_commands[j][5]/10000;
28277 sz += ArrayH::getSize(arrayptr);
28278 if(sz < 19)
28279 {
28280 script_drawing_commands.PopLast();
28281 return;
28282 }
28283
28284 std::vector<int32_t> *v = script_drawing_commands.GetVector();
28285 v->resize(sz, 0);
28286
28287 int32_t* pos = &v->at(0);
28288 int32_t* uv = &v->at(9);
28289 int32_t* col = &v->at(15);
28290 int32_t* size = &v->at(18);
28291
28292 ArrayH::getValues(script_drawing_commands[j][2] / 10000, pos, 8);
28293 ArrayH::getValues(script_drawing_commands[j][3] / 10000, uv, 6);
28294 ArrayH::getValues(script_drawing_commands[j][4] / 10000, col, 3);
28295 ArrayH::getValues(script_drawing_commands[j][5] / 10000, size, 2);
28296
28297 script_drawing_commands[j].SetVector(v);
28298 }
28299 break;
28300
28301 case DRAWSTRINGR:
28302 {
28303 1568537 set_drawing_command_args(j, 9);
28304 // Unused
28305 //const int32_t index = script_drawing_commands[j][19] = j;
28306
28307 1568537 string *str = script_drawing_commands.GetString();
28308 1568537 ArrayH::getString(script_drawing_commands[j][8] / 10000, *str, 256);
28309 1568537 script_drawing_commands[j].SetString(str);
28310 }
28311 1568537 break;
28312
28313 case DRAWSTRINGR2:
28314 {
28315 161166 set_drawing_command_args(j, 11);
28316 // Unused
28317 //const int32_t index = script_drawing_commands[j][19] = j;
28318
28319 161166 string *str = script_drawing_commands.GetString();
28320 161166 ArrayH::getString(script_drawing_commands[j][8] / 10000, *str, 256);
28321 161166 script_drawing_commands[j].SetString(str);
28322 }
28323 161166 break;
28324
28325 case BMPRECTR:
28326 7971 set_user_bitmap_command_args(j, 12); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+12);
28327 //Pop the args off the stack first. Then pop the pointer and push it to sdci[17].
28328 //The pointer for the bitmap variable (its literal value) is always ri->sp+numargs, so, with 12 args, it is sp+12.
28329 7971 break;
28330
28331 case BMPFRAMER:
28332 set_user_bitmap_command_args(j, 9);
28333 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+9);
28334 break;
28335
28336 case CLEARBITMAP:
28337 {
28338 321769 set_user_bitmap_command_args(j, 1);
28339 321769 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+1);
28340 321769 break;
28341 }
28342 case BITMAPCLEARTOCOLOR:
28343 {
28344 2790 set_user_bitmap_command_args(j, 2);
28345 2790 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+2);
28346 2790 break;
28347 }
28348 case REGENERATEBITMAP:
28349 {
28350 26528 set_user_bitmap_command_args(j, 3);
28351 26528 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+3);
28352 26528 break;
28353 }
28354 case BMPPOLYGONR:
28355 {
28356 set_user_bitmap_command_args(j, 5);
28357 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+5);
28358 int32_t arrayptr = script_drawing_commands[j][3]/10000;
28359 if ( !arrayptr ) //Don't crash because of vector size.
28360 {
28361 Z_scripterrlog("Invalid array pointer %d passed to Screen->Polygon(). Aborting.", arrayptr);
28362 break;
28363 }
28364 int32_t sz = ArrayH::getSize(arrayptr);
28365 if(!sz)
28366 {
28367 script_drawing_commands.PopLast();
28368 return;
28369 }
28370 std::vector<int32_t> *v = script_drawing_commands.GetVector();
28371 v->resize(sz, 0);
28372
28373 int32_t* pos = &v->at(0);
28374
28375
28376 ArrayH::getValues(script_drawing_commands[j][3] / 10000, pos, sz);
28377 script_drawing_commands[j].SetVector(v);
28378 }
28379 break;
28380 case READBITMAP:
28381 {
28382 set_user_bitmap_command_args(j, 2);
28383 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+2);
28384 string& user_path = *script_drawing_commands.GetString();
28385 ArrayH::getString(script_drawing_commands[j][2] / 10000, user_path, 256);
28386
28387 if (get_qr(qr_BITMAP_AND_FILESYSTEM_PATHS_ALWAYS_RELATIVE))
28388 {
28389 if (auto r = parse_user_path(user_path, true); !r)
28390 {
28391 scripting_log_error_with_context("Error: {}", r.error());
28392 return;
28393 } else user_path = r.value();
28394 }
28395 else
28396 {
28397 regulate_path(user_path);
28398 }
28399
28400 script_drawing_commands[j].SetString(&user_path);
28401 break;
28402 }
28403 case WRITEBITMAP:
28404 {
28405 set_user_bitmap_command_args(j, 3);
28406 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+3);
28407 std::string& user_path = *script_drawing_commands.GetString();
28408 ArrayH::getString(script_drawing_commands[j][2] / 10000, user_path, 256);
28409
28410 if (get_qr(qr_BITMAP_AND_FILESYSTEM_PATHS_ALWAYS_RELATIVE))
28411 {
28412 if (auto r = parse_user_path(user_path, true); !r)
28413 {
28414 scripting_log_error_with_context("Error: {}", r.error());
28415 return;
28416 } else user_path = r.value();
28417 }
28418 else
28419 {
28420 regulate_path(user_path);
28421 }
28422
28423 script_drawing_commands[j].SetString(&user_path);
28424 break;
28425 }
28426
28427 148823 case BMPCIRCLER: set_user_bitmap_command_args(j, 11); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+11); break;
28428 case BMPARCR: set_user_bitmap_command_args(j, 14); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+14); break;
28429 502 case BMPELLIPSER: set_user_bitmap_command_args(j, 12); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+12); break;
28430 144 case BMPLINER: set_user_bitmap_command_args(j, 11); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+11); break;
28431 case BMPSPLINER: set_user_bitmap_command_args(j, 11); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+11); break;
28432 80910 case BMPPUTPIXELR: set_user_bitmap_command_args(j, 8); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+8); break;
28433 59561 case BMPDRAWTILER: set_user_bitmap_command_args(j, 15); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+15); break;
28434 case BMPDRAWTILECLOAKEDR: set_user_bitmap_command_args(j, 7); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+7); break;
28435 824 case BMPDRAWCOMBOR: set_user_bitmap_command_args(j, 16); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+16); break;
28436 case BMPDRAWCOMBOCLOAKEDR: set_user_bitmap_command_args(j, 7); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+7); break;
28437 167318 case BMPFASTTILER: set_user_bitmap_command_args(j, 6); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+6); break;
28438 32636464 case BMPFASTCOMBOR: set_user_bitmap_command_args(j, 6); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+6); break;
28439 case BMPDRAWCHARR: set_user_bitmap_command_args(j, 10); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+10); break;
28440 case BMPDRAWINTR: set_user_bitmap_command_args(j, 11); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+11); break;
28441 case BMPDRAWSTRINGR:
28442 {
28443 865 set_user_bitmap_command_args(j, 9);
28444 865 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+9);
28445 // Unused
28446 //const int32_t index = script_drawing_commands[j][19] = j;
28447
28448 865 string *str = script_drawing_commands.GetString();
28449 865 ArrayH::getString(script_drawing_commands[j][8] / 10000, *str, 256);
28450 865 script_drawing_commands[j].SetString(str);
28451
28452 }
28453 865 break;
28454 case BMPDRAWSTRINGR2:
28455 {
28456 45504 set_user_bitmap_command_args(j, 11);
28457 45504 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+11);
28458 // Unused
28459 //const int32_t index = script_drawing_commands[j][19] = j;
28460
28461 45504 string *str = script_drawing_commands.GetString();
28462 45504 ArrayH::getString(script_drawing_commands[j][8] / 10000, *str, 256);
28463 45504 script_drawing_commands[j].SetString(str);
28464
28465 }
28466 45504 break;
28467 case BMPQUADR: set_user_bitmap_command_args(j, 16); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+16); break;
28468 case BMPQUAD3DR:
28469 {
28470 set_drawing_command_args(j, 9);
28471 std::vector<int32_t> *v = script_drawing_commands.GetVector();
28472 v->resize(26, 0);
28473
28474 int32_t* pos = &v->at(0);
28475 int32_t* uv = &v->at(12);
28476 int32_t* col = &v->at(20);
28477 int32_t* size = &v->at(24);
28478
28479
28480 ArrayH::getValues(script_drawing_commands[j][2] / 10000, pos, 12);
28481 ArrayH::getValues(script_drawing_commands[j][3] / 10000, uv, 8);
28482 ArrayH::getValues(script_drawing_commands[j][4] / 10000, col, 4);
28483 ArrayH::getValues(script_drawing_commands[j][5] / 10000, size, 2);
28484
28485 script_drawing_commands[j].SetVector(v);
28486 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+9);
28487
28488 }
28489 break;
28490 case BMPTRIANGLER: set_user_bitmap_command_args(j, 14); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+14); break;
28491 case BMPTRIANGLE3DR:
28492 {
28493 set_drawing_command_args(j, 9);
28494
28495 std::vector<int32_t> *v = script_drawing_commands.GetVector();
28496 v->resize(20, 0);
28497
28498 int32_t* pos = &v->at(0);
28499 int32_t* uv = &v->at(9);
28500 int32_t* col = &v->at(15);
28501 int32_t* size = &v->at(18);
28502
28503
28504 ArrayH::getValues(script_drawing_commands[j][2] / 10000, pos, 8);
28505 ArrayH::getValues(script_drawing_commands[j][3] / 10000, uv, 6);
28506 ArrayH::getValues(script_drawing_commands[j][4] / 10000, col, 3);
28507 ArrayH::getValues(script_drawing_commands[j][5] / 10000, size, 2);
28508
28509 script_drawing_commands[j].SetVector(v);
28510 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+9);
28511 break;
28512 }
28513
28514 case BMPDRAWLAYERR:
28515 1173 set_user_bitmap_command_args(j, 8);
28516 1173 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+8);
28517 1173 break;
28518 case BMPDRAWLAYERSOLIDR:
28519 case BMPDRAWLAYERCFLAGR:
28520 case BMPDRAWLAYERCTYPER:
28521 case BMPDRAWLAYERCIFLAGR:
28522 case BMPDRAWLAYERSOLIDITYR: set_user_bitmap_command_args(j, 9); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+9); break;
28523 case BMPDRAWSCREENR:
28524 case BMPDRAWSCREENSOLIDR:
28525 case BMPDRAWSCREENSOLID2R:
28526 case BMPDRAWSCREENCOMBOFR:
28527 case BMPDRAWSCREENCOMBOIR:
28528 case BMPDRAWSCREENCOMBOTR:
28529 2051 set_user_bitmap_command_args(j, 6); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+6); break;
28530 case BITMAPGETPIXEL:
28531 {
28532 set_user_bitmap_command_args(j, 3); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+3);
28533 break;
28534 }
28535 case BMPBLIT:
28536 {
28537 264103 set_user_bitmap_command_args(j, 16);
28538
28539 264103 int bmp_target = SH::read_stack(ri->sp+16);
28540 264103 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = bmp_target;
28541
28542
2/2
✓ Branch 0 taken 263743 times.
✓ Branch 1 taken 360 times.
264103 if (!get_qr(qr_BROKEN_SCRIPTS_BITMAP_DRAW_ORIGIN))
28543 {
28544 360 int bmp_dest = script_drawing_commands[j][2];
28545 720 auto [draw_origin, draw_origin_target] = get_draw_origin_for_draw_command(is_screen_draw, bmp_dest);
28546 360 script_drawing_commands[j].secondary_draw_origin = draw_origin;
28547 360 script_drawing_commands[j].secondary_draw_origin_target = draw_origin_target;
28548 360 }
28549 264103 break;
28550 }
28551 case BMPBLITTO:
28552 {
28553 113329 set_user_bitmap_command_args(j, 16);
28554 113329 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+16);
28555
28556
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if (!get_qr(qr_BROKEN_SCRIPTS_BITMAP_DRAW_ORIGIN))
28557 {
28558 int bmp_source = script_drawing_commands[j][2];
28559 auto [draw_origin, draw_origin_target] = get_draw_origin_for_draw_command(is_screen_draw, bmp_source);
28560 script_drawing_commands[j].secondary_draw_origin = draw_origin;
28561 script_drawing_commands[j].secondary_draw_origin_target = draw_origin_target;
28562 }
28563 113329 break;
28564 }
28565 case TILEBLIT:
28566 {
28567 set_drawing_command_args(j, 17);
28568 break;
28569 }
28570 case COMBOBLIT:
28571 {
28572 set_drawing_command_args(j, 17);
28573 break;
28574 }
28575 case BMPTILEBLIT:
28576 {
28577 set_user_bitmap_command_args(j, 17);
28578 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+17);
28579 break;
28580 }
28581 case BMPCOMBOBLIT:
28582 {
28583 set_user_bitmap_command_args(j, 17);
28584 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+17);
28585 break;
28586 }
28587 case BMPMODE7:
28588 {
28589 set_user_bitmap_command_args(j, 13);
28590 //for(int32_t q = 0; q < 8; ++q )
28591 //Z_scripterrlog("FFscript blit() ri->d[%d] is: %d\n", q, ri->d[q]);
28592 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+13);
28593 break;
28594 }
28595
28596 case BMPWRITETILE:
28597 {
28598 19821648 set_user_bitmap_command_args(j, 6);
28599 19821648 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+6);
28600 19821648 break;
28601 }
28602 case BMPDITHER:
28603 {
28604 set_user_bitmap_command_args(j, 5);
28605 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+5);
28606 break;
28607 }
28608 case BMPMASKDRAW:
28609 {
28610 906 set_user_bitmap_command_args(j, 3);
28611 906 script_drawing_commands[j][4] = 0x01 * 10000L;
28612 906 script_drawing_commands[j][5] = 0xFF * 10000L;
28613 906 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+3);
28614 906 break;
28615 }
28616 case BMPMASKDRAW2:
28617 {
28618 set_user_bitmap_command_args(j, 4);
28619 script_drawing_commands[j][5] = script_drawing_commands[j][4];
28620 script_drawing_commands[j][0] = BMPMASKDRAW;
28621 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+4);
28622 break;
28623 }
28624 case BMPMASKDRAW3:
28625 {
28626 set_user_bitmap_command_args(j, 5);
28627 script_drawing_commands[j][0] = BMPMASKDRAW;
28628 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+5);
28629 break;
28630 }
28631 case BMPMASKBLIT:
28632 {
28633 set_user_bitmap_command_args(j, 4);
28634 script_drawing_commands[j][5] = 0x01 * 10000L;
28635 script_drawing_commands[j][6] = 0xFF * 10000L;
28636 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+4);
28637 break;
28638 }
28639 case BMPMASKBLIT2:
28640 {
28641 set_user_bitmap_command_args(j, 5);
28642 script_drawing_commands[j][6] = script_drawing_commands[j][5];
28643 script_drawing_commands[j][0] = BMPMASKBLIT;
28644 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+5);
28645 break;
28646 }
28647 case BMPMASKBLIT3:
28648 {
28649 set_user_bitmap_command_args(j, 6);
28650 script_drawing_commands[j][0] = BMPMASKBLIT;
28651 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+6);
28652 break;
28653 }
28654 case BMPREPLCOLOR:
28655 case BMPSHIFTCOLOR:
28656 {
28657 7323 set_user_bitmap_command_args(j, 4);
28658 7323 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+4);
28659 7323 break;
28660 }
28661
28662 case DRAWLIGHT_CONE:
28663 case DRAWLIGHT_CIRCLE:
28664 case DRAWLIGHT_SQUARE:
28665 {
28666 // These draw commands implicitly draw at the SPLAYER_DARKROOM_UNDER timing.
28667 // Shift the given args up by one.
28668 int num_args = script_command == DRAWLIGHT_CONE ? 8 : 7;
28669 set_drawing_command_args(j, num_args);
28670 for (int i = num_args; i >= 1; i--)
28671 script_drawing_commands[j][i + 1] = script_drawing_commands[j][i];
28672 script_drawing_commands[j][1] = SPLAYER_DARKROOM_UNDER * 10000;
28673 break;
28674 }
28675 }
28676
28677 int bmp_target;
28678
2/2
✓ Branch 0 taken 45321202 times.
✓ Branch 1 taken 53665002 times.
98986204 if (is_screen_draw)
28679 45321202 bmp_target = zscriptDrawingRenderTarget->GetCurrentRenderTarget() + 10;
28680 else
28681 53665002 bmp_target = script_drawing_commands[j][DRAWCMD_BMP_TARGET];
28682
28683 197972408 auto [draw_origin, draw_origin_target] = get_draw_origin_for_draw_command(is_screen_draw, bmp_target);
28684 98986204 script_drawing_commands[j].draw_origin = draw_origin;
28685 98986204 script_drawing_commands[j].draw_origin_target = draw_origin_target;
28686
28687 98986204 script_drawing_commands.mark_dirty(script_drawing_commands[j][1]/10000);
28688 98986204 }
28689
28690 7069332 void do_set_rendertarget(bool)
28691 {
28692 7069332 int32_t target = int32_t(SH::read_stack(ri->sp) / 10000);
28693 7069332 zscriptDrawingRenderTarget->SetCurrentRenderTarget(target);
28694 7069332 }
28695
28696 339164 void do_sfx(const bool v)
28697 {
28698 339164 int32_t ID = SH::get_arg(sarg1, v) / 10000;
28699
28700
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 339160 times.
339164 if(BC::checkSFXID(ID) != SH::_NoError)
28701 4 return;
28702
28703 339160 sfx(ID);
28704 339164 }
28705
28706 14 void do_sfx_ex(const bool restart)
28707 {
28708 14 int32_t ID = SH::read_stack(ri->sp + 4) / 10000;
28709 14 int32_t vol = vbound(SH::read_stack(ri->sp + 3), 0, 10000 * 100);
28710 14 int32_t pan = vbound(SH::read_stack(ri->sp + 2)/10000 + 128, 0, 255);
28711 14 int32_t freq = SH::read_stack(ri->sp + 1);
28712 14 bool loop = SH::read_stack(ri->sp) / 10000;
28713
28714
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (BC::checkSFXID(ID) != SH::_NoError)
28715 return;
28716
28717
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
14 if (!restart && !sfx_allocated(ID))
28718 return;
28719
28720 14 sfx(ID, pan, loop, restart, vol, freq);
28721 14 }
28722
28723 static int get_sfx_completion()
28724 {
28725 int32_t ID = get_register(sarg1) / 10000;
28726
28727 if (!sfx_allocated(ID))
28728 {
28729 return -10000;
28730 }
28731
28732 int sample_pos = voice_get_position(sfx_voice[ID]);
28733 if (sample_pos < 0)
28734 {
28735 return -10000;
28736 }
28737
28738 uint32_t sample_length = sfx_get_length(ID);
28739 uint64_t res = ((uint64_t)sample_pos * 10000 * 100) / sample_length;
28740 return int32_t(res);
28741 }
28742
28743 void do_get_sfx_completion()
28744 {
28745 int32_t ID = get_register(sarg1) / 10000;
28746 if (replay_is_active())
28747 replay_step_comment(fmt::format("ID {}", ID));
28748 int32_t value = replay_get_state(ReplayStateType::SfxPosition, get_sfx_completion);
28749 set_register(sarg1, value);
28750 }
28751
28752 int32_t FFScript::do_get_internal_uid_npc(int32_t index)
28753 {
28754 return ((int32_t)guys.spr(index)->getUID());
28755 }
28756 int32_t FFScript::do_get_internal_uid_item(int32_t index)
28757 {
28758 return ((int32_t)items.spr(index)->getUID());
28759 }
28760 int32_t FFScript::do_get_internal_uid_lweapon(int32_t index)
28761 {
28762 return ((int32_t)Lwpns.spr(index)->getUID());
28763 }
28764 int32_t FFScript::do_get_internal_uid_eweapon(int32_t index)
28765 {
28766 return ((int32_t)Ewpns.spr(index)->getUID());
28767 }
28768
28769 void FFScript::AlloffLimited(int32_t flagset)
28770 {
28771 clear_bitmap(msg_txt_display_buf);
28772 clear_bitmap(msg_bg_display_buf);
28773 clear_bitmap(msg_portrait_display_buf);
28774 set_clip_state(msg_txt_display_buf, 1);
28775 set_clip_state(msg_bg_display_buf, 1);
28776 set_clip_state(msg_portrait_display_buf, 1);
28777
28778
28779 clear_bitmap(pricesdisplaybuf);
28780 set_clip_state(pricesdisplaybuf, 1);
28781
28782 if(items.idCount(iPile))
28783 {
28784 loadlvlpal(DMaps[cur_dmap].color);
28785 }
28786
28787 /*
28788
28789 #define warpFlagCLEARITEMS 0x200
28790 #define warpFlagCLEARGUYS 0x400
28791 #define warpFlagCLEARLWEAPONS 0x800
28792 #define warpFlagCLEAREWEAPONS 0x1000
28793 #define warpFlagCLEARHOOKSHOT 0x2000
28794 #define warpFlagCLEARDECORATIONS 0x4000
28795 #define warpFlagCLEARPARTICLES 0x8000
28796 */
28797
28798 if ( (flagset&warpFlagCLEARITEMS) ) items.clear();
28799 if ( (flagset&warpFlagCLEARGUYS) ) guys.clear();
28800 if ( (flagset&warpFlagCLEARLWEAPONS) ) Lwpns.clear();
28801 if ( (flagset&warpFlagCLEAREWEAPONS) ) Ewpns.clear();
28802 if ( (flagset&warpFlagCLEARHOOKSHOT) )
28803 {
28804 chainlinks.clear();
28805 Hero.reset_hookshot();
28806 }
28807 if ( (flagset&warpFlagCLEARDECORATIONS) ) decorations.clear();
28808 if ( (flagset&warpFlagCLEARPARTICLES) ) particles.clear();
28809 clearScriptHelperData();
28810
28811
28812
28813 clearScriptHelperData();
28814
28815 lensclk = 0;
28816 lensid=-1;
28817 drawguys=true;
28818 down_control_states[btnUp] =
28819 down_control_states[btnDown] =
28820 down_control_states[btnLeft] =
28821 down_control_states[btnRight] =
28822 down_control_states[btnA] =
28823 down_control_states[btnB] =
28824 down_control_states[btnS] = true;
28825
28826 if(watch && !cheat_superman)
28827 {
28828 Hero.setClock(false);
28829 }
28830
28831 watch=freeze_guys=loaded_guys=blockpath=false;
28832
28833 activation_counters.clear();
28834 activation_counters_ffc.clear();
28835 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
28836 get_screen_state(scr->screen).loaded_enemies = false;
28837 });
28838
28839 sle_clk=0;
28840
28841 if(usebombpal)
28842 {
28843 memcpy(RAMpal, tempbombpal, PAL_SIZE*sizeof(RGB));
28844 refreshpal=true;
28845 usebombpal=false;
28846 }
28847
28848
28849 }
28850
28851 188 void doWarpEffect(int32_t warpEffect, bool out)
28852 {
28853
3/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 156 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
✓ Branch 5 taken 8 times.
188 switch(warpEffect)
28854 {
28855 case warpEffectZap:
28856 if(out) zapout();
28857 else zapin();
28858 break;
28859 case warpEffectWave:
28860
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(out) wavyout(false);
28861 12 else wavyin();
28862 24 break;
28863 case warpEffectInstant:
28864 if(out) blackscr(30,true);
28865 break;
28866 case warpEffectMozaic:
28867 //!TODO Unimplemented
28868 break;
28869 case warpEffectOpen:
28870
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if(out) closescreen();
28871 4 else openscreen();
28872 8 break;
28873 }
28874 188 }
28875
28876 12 void FFScript::queueWarp(int32_t wtype, int32_t tdm, int32_t tscr, int32_t wx, int32_t wy,
28877 int32_t weff, int32_t wsfx, int32_t wflag, int32_t wdir)
28878 {
28879 12 warpex[wexActive] = 1;
28880 12 warpex[wexType] = wtype;
28881 12 warpex[wexDMap] = tdm;
28882 12 warpex[wexScreen] = tscr;
28883 12 warpex[wexX] = wx;
28884 12 warpex[wexY] = wy;
28885 12 warpex[wexEffect] = weff;
28886 12 warpex[wexSound] = wsfx;
28887 12 warpex[wexFlags] = wflag;
28888 12 warpex[wexDir] = wdir;
28889 12 }
28890
28891 104 bool FFScript::warp_player(int32_t warpType, int32_t dmap, int32_t screen, int32_t warpDestX, int32_t warpDestY, int32_t warpEffect, int32_t warpSound, int32_t warpFlags, int32_t heroFacesDir)
28892 {
28893 if(DEVLOGGING)
28894 {
28895 zprint("FFScript::warp_player() arg %s is: %d \n", "warpType", warpType);
28896 zprint("FFScript::warp_player() arg %s is: %d \n", "dmap", dmap);
28897 zprint("FFScript::warp_player() arg %s is: %d \n", "screen", screen);
28898 zprint("FFScript::warp_player() arg %s is: %d \n", "warpDestX", warpDestX);
28899 zprint("FFScript::warp_player() arg %s is: %d \n", "warpDestY", warpDestY);
28900 zprint("FFScript::warp_player() arg %s is: %d \n", "warpEffect", warpEffect);
28901 zprint("FFScript::warp_player() arg %s is: %d \n", "warpSound", warpSound);
28902 zprint("FFScript::warp_player() arg %s is: %d \n", "warpFlags", warpFlags);
28903 zprint("FFScript::warp_player() arg %s is: %d \n", "heroFacesDir", heroFacesDir);
28904 }
28905
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
104 if ( ((unsigned)dmap) >= MAXDMAPS )
28906 {
28907 Z_scripterrlog("Invalid DMap ID (%d) passed to WarpEx(). Aborting.\n", dmap);
28908 return false;
28909 }
28910
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
104 if ( ((unsigned)screen) >= MAPSCRS )
28911 {
28912 Z_scripterrlog("Invalid Screen Index (%d) passed to WarpEx(). Aborting.\n", screen);
28913 return false;
28914 }
28915 //Extra sanity guard.
28916
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
104 if ( map_screen_index(DMaps[dmap].map, screen + DMaps[dmap].xoff) >= (int32_t)TheMaps.size() )
28917 {
28918 Z_scripterrlog("Invalid destination passed to WarpEx(). Aborting.\n");
28919 return false;
28920 }
28921 104 byte t = 0;
28922 104 t=(cur_screen<128)?0:1;
28923 104 bool overlay=false;
28924 104 bool intradmap = (dmap == cur_dmap);
28925 104 int32_t olddmap = cur_dmap;
28926 //if ( intradmap )
28927 //{
28928 // initZScriptDMapScripts(); //Not needed.
28929 //}
28930
28931
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
104 if ( warpType == wtNOWARP ) { Z_eventlog("Used a Cancel Warped to DMap %d: %s, screen %d", cur_dmap, DMaps[cur_dmap].name,cur_screen); return false; }
28932 104 int32_t dest_map = DMaps[dmap].map;
28933 104 int32_t mapID = dest_map + 1;
28934 104 int32_t dest_dmap_xoff = DMaps[dmap].xoff;
28935 104 int32_t dest_screen = dest_dmap_xoff + screen;
28936 //mapscr *m = &TheMaps[mapID * MAPSCRS + scrID];
28937
1/2
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
104 mapscr *m = &TheMaps[(zc_max((mapID)-1,0) * MAPSCRS + dest_screen)];
28938
1/2
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
104 if ( warpFlags&warpFlagNOSTEPFORWARD ) FFCore.temp_no_stepforward = 1;
28939 104 int32_t wx = 0, wy = 0;
28940
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 85 times.
104 if ( warpDestX < 0 )
28941 {
28942 if(DEVLOGGING) zprint("WarpEx() was set to warp return point:%d\n", warpDestY);
28943
2/2
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 10 times.
85 if ( (unsigned)warpDestY < 4 )
28944 {
28945 75 wx = m->warpreturnx[warpDestY];
28946 75 wy = m->warpreturny[warpDestY];
28947 if(DEVLOGGING)
28948 {
28949 zprint("WarpEx Return Point X is: %d\n",wx);
28950 zprint("WarpEx Return Point Y is: %d\n",wy);
28951 }
28952 75 }
28953 else
28954 {
28955
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
10 if ( warpDestY == 5 || warpDestY < 0)
28956 {
28957 //Pit warp
28958 10 wx = Hero.getX();
28959 10 wy = Hero.getY();
28960 10 }
28961 else
28962 {
28963 Z_scripterrlog("Invalid Warp Return Square Type (%d) provided as an arg to Hero->WarpEx().\n",warpDestY);
28964 return false;
28965 }
28966 }
28967 85 }
28968 else
28969 {
28970 region_t region;
28971 int rx, ry;
28972 19 calculate_region(dest_map, dest_screen, region, rx, ry);
28973
2/4
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19 times.
19 if ( (unsigned)warpDestX < region.width && (unsigned)warpDestY < region.height )
28974 {
28975 19 wx = warpDestX;
28976 19 wy = warpDestY;
28977 19 }
28978 else
28979 {
28980 Z_scripterrlog("Invalid pixel coordinates of x = %d, y = %d, supplied to Hero->WarpEx()\n",warpDestX,warpDestY);
28981 return false;
28982 }
28983 }
28984 //warp coordinates are wx, wy, not x, y! -Z
28985
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 50 times.
104 if ( !(warpFlags&warpFlagDONTKILLSCRIPTDRAWS) ) script_drawing_commands.Clear();
28986 //we also need to check if dmaps are sideview here! -Z
28987 //Likewise, we need to add that check to the normal Hero:;dowarp(0
28988 104 bool wasSideview = isSideViewGravity(t);
28989
28990 //int32_t last_entr_scr = -1;
28991 //int32_t last_entr_dmap = -1;
28992
28993
1/2
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
104 if ( warpType < wtEXIT ) warpType = wtIWARP; //Sanity check. We can't use wtCave, or wtPassage, with scritped warps at present.
28994 104 Hero.is_warping = true;
28995
2/5
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
104 switch(warpType)
28996 {
28997 case wtIWARP:
28998 case wtIWARPBLK:
28999 case wtIWARPOPEN:
29000 case wtIWARPZAP:
29001 case wtIWARPWAVE:
29002 {
29003 94 bool wasswimming = (Hero.getAction()==swimming);
29004 94 bool wassideswim = (Hero.getAction()==sideswimming);
29005 94 int32_t olddiveclk = Hero.diveclk;
29006
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 94 times.
94 if ( !(warpFlags&warpFlagDONTCLEARSPRITES) )
29007 {
29008 94 ALLOFF();
29009 94 }
29010 else FFCore.AlloffLimited(warpFlags);
29011
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 78 times.
94 if (warpFlags&warpFlagFORCERESETMUSIC) music_stop();
29012
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 40 times.
94 if ( !(warpFlags&warpFlagDONTKILLSOUNDS) ) kill_sfx();
29013 94 sfx(warpSound);
29014
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 if(wasswimming)
29015 {
29016 Hero.setAction(swimming); FFCore.setHeroAction(swimming);
29017 Hero.diveclk = olddiveclk;
29018 }
29019
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 if(wassideswim)
29020 {
29021 Hero.setAction(sideswimming); FFCore.setHeroAction(sideswimming);
29022 Hero.diveclk = 0;
29023 }
29024 94 doWarpEffect(warpEffect, true);
29025 94 int32_t c = DMaps[cur_dmap].color;
29026 94 bool changedlevel = false;
29027 94 bool changeddmap = false;
29028
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 70 times.
94 if(cur_dmap != dmap)
29029 {
29030 70 timeExitAllGenscript(GENSCR_ST_CHANGE_DMAP);
29031 70 changeddmap = true;
29032 70 }
29033
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 52 times.
94 if(dlevel != DMaps[dmap].level)
29034 {
29035 52 timeExitAllGenscript(GENSCR_ST_CHANGE_LEVEL);
29036 52 changedlevel = true;
29037 52 }
29038 94 dlevel = DMaps[dmap].level;
29039 94 cur_dmap = dmap;
29040
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 70 times.
94 if(changeddmap)
29041 {
29042 70 throwGenScriptEvent(GENSCR_EVENT_CHANGE_DMAP);
29043 70 }
29044
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 52 times.
94 if(changedlevel)
29045 {
29046 52 throwGenScriptEvent(GENSCR_EVENT_CHANGE_LEVEL);
29047 52 }
29048 94 cur_map = DMaps[cur_dmap].map;
29049 94 init_dmap();
29050 94 update_subscreens(dmap);
29051
29052 94 ringcolor(false);
29053
29054
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 70 times.
94 if(DMaps[cur_dmap].color != c)
29055 70 loadlvlpal(DMaps[cur_dmap].color);
29056
29057 94 lightingInstant(); // Also sets naturaldark
29058 94 int prev_screen = hero_screen;
29059 94 loadscr(cur_dmap, screen + DMaps[cur_dmap].xoff, -1, overlay);
29060
29061 // In the case where we did not call ALLOFF, preserve the "enemies have spawned"
29062 // state for the new screen.
29063
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 if (warpFlags&warpFlagDONTCLEARSPRITES)
29064 {
29065 if (get_screen_state(prev_screen).loaded_enemies)
29066 get_screen_state(hero_screen).loaded_enemies = true;
29067 }
29068
29069 94 Hero.x = (zfix)wx;
29070 94 Hero.y = (zfix)wy;
29071 94 update_viewport();
29072
29073
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 28 times.
94 switch(heroFacesDir)
29074 {
29075 case up:
29076 case down:
29077 case left:
29078 case right:
29079 66 Hero.dir = heroFacesDir;
29080 66 break;
29081 default:
29082
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 if((int32_t)Hero.x==(zfix)0)
29083 {
29084 Hero.dir=right;
29085 }
29086
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 if((int32_t)Hero.x==(zfix)240)
29087 {
29088 Hero.dir=left;
29089 }
29090
29091
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 if((int32_t)Hero.y==(zfix)0)
29092 {
29093 Hero.dir=down;
29094 }
29095
29096
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 if((int32_t)Hero.y==(zfix)160)
29097 {
29098 Hero.dir=up;
29099 }
29100 28 }
29101
29102 94 markBmap(Hero.dir^1, hero_screen);
29103
29104
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 94 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 94 times.
94 if(iswaterex_z3(MAPCOMBO((int32_t)Hero.x,(int32_t)Hero.y+8), -1, Hero.x, Hero.y+8, true) && _walkflag((int32_t)Hero.x,(int32_t)Hero.y+8,0) && current_item(itype_flippers))
29105 {
29106 Hero.hopclk=0xFF;
29107 Hero.attackclk = Hero.charging = Hero.spins = 0;
29108 if (isSideViewHero() && get_qr(qr_SIDESWIM)) {Hero.setAction(sideswimming); FFCore.setHeroAction(sideswimming);}
29109 else {Hero.setAction(swimming); FFCore.setHeroAction(swimming);}
29110 }
29111 else
29112 {
29113 94 Hero.setAction(none); FFCore.setHeroAction(none);
29114 }
29115
29116 //preloaded freeform combos
29117 94 ffscript_engine(true);
29118
29119 94 putscr(hero_scr, scrollbuf, 0, 0);
29120 94 putscrdoors(hero_scr, scrollbuf, 0, 0);
29121
29122 94 doWarpEffect(warpEffect, false);
29123 94 show_subscreen_life=true;
29124 94 show_subscreen_numbers=true;
29125
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 90 times.
94 if (!(warpFlags&warpFlagFORCECONTINUEMUSIC)) Play_Level_Music();
29126 94 currcset=DMaps[cur_dmap].color;
29127 94 dointro();
29128 94 Hero.set_respawn_point();
29129 94 Hero.trySideviewLadder();
29130
29131 94 break;
29132 }
29133
29134
29135 case wtEXIT:
29136 {
29137 lighting(false,false,pal_litRESETONLY);//Reset permLit, and do nothing else; lighting was not otherwise called on a wtEXIT warp.
29138 ALLOFF();
29139 if (warpFlags&warpFlagFORCERESETMUSIC) music_stop();
29140 if ( !(warpFlags&warpFlagDONTKILLSOUNDS) ) kill_sfx();
29141 sfx(warpSound);
29142 blackscr(30,false);
29143 bool changedlevel = false;
29144 bool changeddmap = false;
29145 if(cur_dmap != dmap)
29146 {
29147 timeExitAllGenscript(GENSCR_ST_CHANGE_DMAP);
29148 changeddmap = true;
29149 }
29150 if(dlevel != DMaps[dmap].level)
29151 {
29152 timeExitAllGenscript(GENSCR_ST_CHANGE_LEVEL);
29153 changedlevel = true;
29154 }
29155 dlevel = DMaps[dmap].level;
29156 cur_dmap = dmap;
29157 if(changeddmap)
29158 {
29159 throwGenScriptEvent(GENSCR_EVENT_CHANGE_DMAP);
29160 }
29161 if(changedlevel)
29162 {
29163 throwGenScriptEvent(GENSCR_EVENT_CHANGE_LEVEL);
29164 }
29165 cur_map=DMaps[cur_dmap].map;
29166 init_dmap();
29167 update_subscreens(dmap);
29168 loadfullpal();
29169 ringcolor(false);
29170 loadlvlpal(DMaps[cur_dmap].color);
29171 loadscr(cur_dmap, screen + DMaps[cur_dmap].xoff, -1, overlay);
29172
29173 if((hero_scr->flags&fDARK) && !get_qr(qr_NEW_DARKROOM))
29174 {
29175 if(get_qr(qr_FADE))
29176 {
29177 interpolatedfade();
29178 }
29179 else
29180 {
29181 loadfadepal((DMaps[cur_dmap].color)*pdLEVEL+poFADE3);
29182 }
29183
29184 darkroom=naturaldark=true;
29185 }
29186 else
29187 {
29188 darkroom=naturaldark=false;
29189 }
29190
29191
29192 //Move Hero's coordinates
29193 Hero.x = (zfix)wx;
29194 Hero.y = (zfix)wy;
29195 update_viewport();
29196
29197 //set his dir
29198 switch(heroFacesDir)
29199 {
29200 case up:
29201 case down:
29202 case left:
29203 case right:
29204 Hero.dir = heroFacesDir;
29205 break;
29206 default:
29207 Hero.dir=down;
29208 if((int32_t)Hero.x==(zfix)0)
29209 {
29210 Hero.dir=right;
29211 }
29212 if((int32_t)Hero.x==(zfix)240)
29213 {
29214 Hero.dir=left;
29215 }
29216
29217 if((int32_t)Hero.y==(zfix)0)
29218 {
29219 Hero.dir=down;
29220 }
29221
29222 if((int32_t)Hero.y==(zfix)160)
29223 {
29224 Hero.dir=up;
29225 }
29226 }
29227
29228 if(dlevel)
29229 {
29230 // reset enemy kill counts
29231 for(int32_t i=0; i<128; i++)
29232 {
29233 int mi = mapind(cur_map, i);
29234 game->guys[mi] = 0;
29235 game->maps[mi] &= ~mTMPNORET;
29236 }
29237 }
29238
29239 markBmap(Hero.dir^1, hero_screen);
29240 //preloaded freeform combos
29241 ffscript_engine(true);
29242 Hero.reset_hookshot();
29243
29244 if(isdungeon())
29245 {
29246 openscreen();
29247 if(get_er(er_SHORTDGNWALK)==0 && get_qr(qr_SHORTDGNWALK)==0)
29248 Hero.stepforward(Hero.diagonalMovement?11:12, false);
29249 else
29250 // Didn't walk as far pre-1.93, and some quests depend on that
29251 Hero.stepforward(8, false);
29252 }
29253 else
29254 {
29255 openscreen();
29256 }
29257
29258 show_subscreen_life=true;
29259 show_subscreen_numbers=true;
29260 if (!(warpFlags&warpFlagFORCECONTINUEMUSIC))Play_Level_Music();
29261 currcset=DMaps[cur_dmap].color;
29262 dointro();
29263 Hero.set_respawn_point();
29264 Hero.trySideviewLadder();
29265
29266 for(int32_t i=0; i<6; i++)
29267 visited[i]=-1;
29268
29269 //last_entr_scr = scrID;
29270 //last_entr_dmap = dmapID;
29271
29272 break;
29273
29274 }
29275 case wtSCROLL: // scrolling warp
29276 {
29277 10 int32_t c = DMaps[cur_dmap].color;
29278 10 scrolling_dmap = cur_dmap;
29279 10 scrolling_map = cur_map;
29280 10 cur_map = DMaps[dmap].map;
29281 10 update_subscreens(dmap);
29282
29283 10 dlevel = DMaps[dmap].level;
29284 //check if Hero has the map for the new location before updating the subscreen. ? -Z
29285 //This works only in one direction, if Hero had a map, to not having one.
29286 //If Hero does not have a map, and warps somewhere where he does, then the map still briefly shows.
29287 10 update_subscreens(dmap);
29288
29289 // if ( has_item(itype_map, dlevel) )
29290 // {
29291 // //Blank the map during an intra-dmap scrolling warp.
29292 // dlevel = -1; //a hack for the minimap. This works!! -Z
29293 // }
29294
29295 // fix the scrolling direction, if it was a tile or instant warp
29296 10 Hero.sdir = vbound(Hero.dir,0,3);
29297
29298
29299 10 Hero.scrollscr(Hero.sdir, screen+DMaps[dmap].xoff, dmap);
29300 10 bool changedlevel = false;
29301 10 bool changeddmap = false;
29302
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(cur_dmap != dmap)
29303 {
29304 timeExitAllGenscript(GENSCR_ST_CHANGE_DMAP);
29305 changeddmap = true;
29306 }
29307
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(dlevel != DMaps[dmap].level)
29308 {
29309 timeExitAllGenscript(GENSCR_ST_CHANGE_LEVEL);
29310 changedlevel = true;
29311 }
29312 10 dlevel = DMaps[dmap].level;
29313 10 cur_dmap = dmap;
29314
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(changeddmap)
29315 {
29316 throwGenScriptEvent(GENSCR_EVENT_CHANGE_DMAP);
29317 }
29318
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(changedlevel)
29319 {
29320 throwGenScriptEvent(GENSCR_EVENT_CHANGE_LEVEL);
29321 }
29322
29323 10 Hero.reset_hookshot();
29324
29325
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(!intradmap)
29326 {
29327
5/8
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 10 times.
10 if(((wx>0||wy>0)||(get_qr(qr_WARPSIGNOREARRIVALPOINT)))&&(!get_qr(qr_NOSCROLLCONTINUE))&&(!(hero_scr->flags6&fNOCONTINUEHERE)))
29328 {
29329
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 6 times.
10 if(dlevel)
29330 {
29331 6 lastentrance = cur_screen;
29332 6 }
29333 else
29334 {
29335 4 lastentrance = DMaps[cur_dmap].cont + DMaps[cur_dmap].xoff;
29336 }
29337
29338 10 lastentrance_dmap = dmap;
29339 10 }
29340 10 }
29341
29342
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(DMaps[cur_dmap].color != c)
29343 {
29344 lighting(false, true);
29345 }
29346
29347
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (!(warpFlags&warpFlagFORCECONTINUEMUSIC)) Play_Level_Music();
29348 10 currcset=DMaps[cur_dmap].color;
29349 10 dointro();
29350 10 break;
29351 }
29352 //Cannot use these types with scripts, or with strings.
29353 case wtCAVE:
29354 case wtPASS:
29355 case wtWHISTLE:
29356 default:
29357 {
29358 Z_scripterrlog("Invalid warp type (%d) supplied to Hero->WarpEx()!. Cannot warp!!\n", warpType);
29359 Hero.is_warping = false;
29360 return false;
29361 }
29362 }
29363 // Stop Hero from drowning!
29364
1/2
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
104 if(Hero.getAction()==drowning)
29365 {
29366 Hero.drownclk=0;
29367 Hero.setAction(none); FFCore.setHeroAction(none);
29368 }
29369
29370 // But keep him swimming if he ought to be!
29371
3/8
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 104 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 104 times.
✗ Branch 7 not taken.
104 if(Hero.getAction()!=rafting && iswaterex_z3(MAPCOMBO((int32_t)Hero.x,(int32_t)Hero.y+8), -1, Hero.x, Hero.y+8, true) && (_walkflag((int32_t)Hero.x,(int32_t)Hero.y+8,0) || get_qr(qr_DROWN))
29372 && (current_item(itype_flippers)) && (Hero.getAction()!=inwind))
29373 {
29374 Hero.hopclk=0xFF;
29375 if (isSideViewHero() && get_qr(qr_SIDESWIM)) {Hero.setAction(sideswimming); FFCore.setHeroAction(sideswimming);}
29376 else {Hero.setAction(swimming); FFCore.setHeroAction(swimming);}
29377 }
29378
29379 104 newscr_clk=frame;
29380 104 activated_timed_warp=false;
29381 104 eat_buttons();
29382
29383
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 26 times.
104 if(warpType!=wtIWARP) { Hero.attackclk=0; }
29384
29385 104 Hero.didstuff=0;
29386 104 Hero.usecounts.clear();
29387 104 map_bkgsfx(true);
29388 104 loadside=Hero.dir^1;
29389 104 whistleclk=-1;
29390
29391
2/4
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 104 times.
✗ Branch 3 not taken.
104 if(((int32_t)Hero.z>0 || (int32_t)Hero.fakez>0) && isSideViewHero())
29392 {
29393 Hero.y-=Hero.z;
29394 Hero.y-=Hero.fakez;
29395 Hero.z=0;
29396 Hero.fakez=0;
29397 }
29398
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
104 else if(!isSideViewHero())
29399 {
29400 104 Hero.fall=0;
29401 104 Hero.fakefall=0;
29402 104 }
29403
29404 // If warping between top-down and sideview screens,
29405 // fix enemies that are carried over by Full Screen Warp
29406 104 const bool tmpscr_is_sideview = isSideViewGravity();
29407
29408
2/4
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 104 times.
✗ Branch 3 not taken.
104 if(!wasSideview && tmpscr_is_sideview)
29409 {
29410 for(int32_t i=0; i<guys.Count(); i++)
29411 {
29412 if(guys.spr(i)->z > 0)
29413 {
29414 guys.spr(i)->y -= guys.spr(i)->z;
29415 guys.spr(i)->z = 0;
29416 }
29417
29418 if(((enemy*)guys.spr(i))->family!=eeTRAP && ((enemy*)guys.spr(i))->family!=eeSPINTILE)
29419 guys.spr(i)->yofs += 2;
29420 }
29421 }
29422
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
104 else if(wasSideview && !tmpscr_is_sideview)
29423 {
29424 for(int32_t i=0; i<guys.Count(); i++)
29425 {
29426 if(((enemy*)guys.spr(i))->family!=eeTRAP && ((enemy*)guys.spr(i))->family!=eeSPINTILE)
29427 guys.spr(i)->yofs -= 2;
29428 }
29429 }
29430
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
104 if ( warpType == wtEXIT )
29431 {
29432 game->set_continue_scrn(cur_screen);
29433 game->set_continue_dmap(dmap);
29434 lastentrance = cur_screen;
29435 lastentrance_dmap = dmap;
29436 }
29437 else
29438 {
29439
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 4 times.
104 if ( (warpFlags&warpFlagSETENTRANCESCREEN) ) lastentrance = cur_screen;
29440
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 4 times.
104 if ( (warpFlags&warpFlagSETENTRANCEDMAP) ) lastentrance_dmap = dmap;
29441
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 4 times.
104 if ( (warpFlags&warpFlagSETCONTINUESCREEN) ) game->set_continue_scrn(cur_screen);
29442
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 4 times.
104 if ( (warpFlags&warpFlagSETCONTINUEDMAP) ) game->set_continue_dmap(dmap);
29443 }
29444
1/2
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
104 if(hero_scr->flags4&fAUTOSAVE)
29445 {
29446 save_game(true,0);
29447 }
29448
29449
2/2
✓ Branch 0 taken 103 times.
✓ Branch 1 taken 1 times.
104 if(hero_scr->flags6&fCONTINUEHERE)
29450 {
29451 1 lastentrance_dmap = cur_dmap;
29452 1 lastentrance = home_screen;
29453 1 }
29454
29455 104 update_subscreens();
29456 104 verifyBothWeapons();
29457 208 Z_eventlog("Warped to DMap %d: %s, screen %d, via %s.\n", cur_dmap, DMaps[cur_dmap].name,cur_screen,
29458
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
208 warpType==wtEXIT ? "Entrance/Exit" :
29459
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 94 times.
104 warpType==wtSCROLL ? "Scrolling Warp" :
29460 94 warpType==wtNOWARP ? "Cancel Warp" :
29461 "Insta-Warp");
29462
29463 104 eventlog_mapflags();
29464
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
104 if (((warpFlags&warpFlagDONTRESTARTDMAPSCRIPT) != 0) == (get_qr(qr_SCRIPT_WARPS_DMAP_SCRIPT_TOGGLE) != 0)|| olddmap != cur_dmap) //Changed DMaps, or needs to reset the script
29465 {
29466 104 FFScript::deallocateAllScriptOwned(ScriptType::DMap, olddmap);
29467 104 initZScriptDMapScripts();
29468 104 }
29469 104 Hero.is_warping = false;
29470
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 88 times.
104 if(!get_qr(qr_SCROLLWARP_NO_RESET_FRAME))
29471 88 GameFlags |= GAMEFLAG_RESET_GAME_LOOP;
29472 104 return true;
29473 104 }
29474
29475 2004 void FFScript::do_adjustvolume(const bool v)
29476 {
29477
1/2
✓ Branch 0 taken 2004 times.
✗ Branch 1 not taken.
2004 if (get_qr(qr_OLD_SCRIPT_VOLUME))
29478 {
29479 2004 int32_t perc = (SH::get_arg(sarg1, v) / 10000);
29480 2004 float pct = perc / 100.0;
29481 2004 float temp_midi = 0;
29482 2004 float temp_digi = 0;
29483 2004 float temp_mus = 0;
29484
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 4 times.
2004 if (!(coreflags & FFCORE_SCRIPTED_MIDI_VOLUME))
29485 {
29486 4 temp_midi = do_getMIDI_volume();
29487 4 usr_midi_volume = do_getMIDI_volume();
29488 4 SetFFEngineFlag(FFCORE_SCRIPTED_MIDI_VOLUME, true);
29489 4 }
29490 else
29491 {
29492 2000 temp_midi = (float)usr_midi_volume;
29493 }
29494
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 4 times.
2004 if (!(coreflags & FFCORE_SCRIPTED_DIGI_VOLUME))
29495 {
29496 4 temp_digi = do_getDIGI_volume();
29497 4 usr_digi_volume = do_getDIGI_volume();
29498 4 SetFFEngineFlag(FFCORE_SCRIPTED_DIGI_VOLUME, true);
29499 4 }
29500 else
29501 {
29502 2000 temp_digi = (float)usr_digi_volume;
29503 }
29504
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 4 times.
2004 if (!(coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME))
29505 {
29506 4 temp_mus = do_getMusic_volume();
29507 4 usr_music_volume = do_getMusic_volume();
29508 4 SetFFEngineFlag(FFCORE_SCRIPTED_MUSIC_VOLUME, true);
29509 4 }
29510 else
29511 {
29512 2000 temp_mus = (float)usr_music_volume;
29513 }
29514
29515 2004 temp_midi *= pct;
29516 2004 temp_digi *= pct;
29517 2004 temp_mus *= pct;
29518 2004 do_setMIDI_volume((int32_t)temp_midi);
29519 2004 do_setDIGI_volume((int32_t)temp_digi);
29520 2004 do_setMusic_volume((int32_t)temp_mus);
29521 2004 }
29522 else
29523 {
29524 int32_t perc = SH::get_arg(sarg1, v);
29525 FFCore.usr_music_volume = vbound(perc, 0, 10000 * 100);
29526
29527 if (zcmusic != NULL)
29528 {
29529 if (zcmusic->playing != ZCM_STOPPED)
29530 {
29531 int32_t temp_volume = emusic_volume;
29532 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
29533 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
29534 temp_volume = (temp_volume * zcmusic->fadevolume) / 10000;
29535 zcmusic_play(zcmusic, temp_volume);
29536 return;
29537 }
29538 }
29539 else if (currmidi > -1)
29540 {
29541 jukebox(currmidi);
29542 master_volume(digi_volume, midi_volume);
29543 }
29544 }
29545 2004 }
29546
29547 void FFScript::do_adjustsfxvolume(const bool v)
29548 {
29549 if (get_qr(qr_OLD_SCRIPT_VOLUME))
29550 {
29551 int32_t perc = (SH::get_arg(sarg1, v) / 10000);
29552 float pct = perc / 100.0;
29553 float temp_sfx = 0;
29554 if (!(coreflags & FFCORE_SCRIPTED_SFX_VOLUME))
29555 {
29556 temp_sfx = do_getSFX_volume();
29557 usr_sfx_volume = (int32_t)temp_sfx;
29558 SetFFEngineFlag(FFCORE_SCRIPTED_SFX_VOLUME, true);
29559 }
29560 else
29561 {
29562 temp_sfx = (float)usr_sfx_volume;
29563 }
29564 temp_sfx *= pct;
29565 do_setSFX_volume((int32_t)temp_sfx);
29566 }
29567 else
29568 {
29569 int32_t perc = SH::get_arg(sarg1, v);
29570 FFCore.usr_sfx_volume = vbound(perc, 0, 10000 * 100);
29571 }
29572 }
29573
29574
29575 63829 void do_midi(bool v)
29576 {
29577 63829 int32_t MIDI = SH::get_arg(sarg1, v) / 10000;
29578
29579
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 63786 times.
63829 if(MIDI == 0)
29580 43 music_stop();
29581 else
29582 63786 jukebox(MIDI + (ZC_MIDI_COUNT - 1));
29583 63829 }
29584
29585
29586 1 void stop_sfx(const bool v)
29587 {
29588 1 int32_t ID = SH::get_arg(sarg1, v) / 10000;
29589 1 int32_t sfx = (int32_t)ID;
29590
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(BC::checkSFXID(ID) != SH::_NoError)
29591 return;
29592 1 stop_sfx(sfx);
29593 1 }
29594
29595 void pause_sfx(const bool v)
29596 {
29597 int32_t ID = SH::get_arg(sarg1, v) / 10000;
29598 int32_t sfx = (int32_t)ID;
29599 if(BC::checkSFXID(ID) != SH::_NoError)
29600 return;
29601 pause_sfx(sfx);
29602 }
29603
29604 void resume_sfx(const bool v)
29605 {
29606 int32_t ID = SH::get_arg(sarg1, v) / 10000;
29607 int32_t sfx = (int32_t)ID;
29608 if(BC::checkSFXID(ID) != SH::_NoError)
29609 return;
29610 resume_sfx(sfx);
29611 }
29612
29613
29614
29615 178 void do_enh_music(bool v)
29616 {
29617 178 int32_t arrayptr = SH::get_arg(sarg1, v) / 10000;
29618 178 int32_t track = (SH::get_arg(sarg2, v) / 10000)-1;
29619
29620
1/2
✓ Branch 0 taken 178 times.
✗ Branch 1 not taken.
178 if(arrayptr == 0)
29621 music_stop();
29622 else // Pointer to a string..
29623 {
29624 178 string filename_str;
29625 char filename_char[256];
29626 bool ret;
29627
1/2
✓ Branch 0 taken 178 times.
✗ Branch 1 not taken.
178 ArrayH::getString(arrayptr, filename_str, 256);
29628 178 strncpy(filename_char, filename_str.c_str(), 255);
29629 178 filename_char[255]='\0';
29630
2/4
✓ Branch 0 taken 178 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 178 times.
✗ Branch 3 not taken.
178 ret=try_zcmusic(filename_char, qstpath, track, -1000, get_emusic_volume());
29631
1/2
✓ Branch 0 taken 178 times.
✗ Branch 1 not taken.
178 set_register(sarg2, ret ? 10000 : 0);
29632 178 }
29633 178 }
29634
29635 5 void do_enh_music_crossfade()
29636 {
29637 5 int32_t arrayptr = SH::read_stack(ri->sp + 5) / 10000;
29638 5 int32_t track = SH::read_stack(ri->sp + 4) / 10000;
29639
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 int32_t fadeoutframes = zc_max(SH::read_stack(ri->sp + 3) / 10000, 0);
29640
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 int32_t fadeinframes = zc_max(SH::read_stack(ri->sp + 2) / 10000, 0);
29641 5 int32_t fademiddleframes = SH::read_stack(ri->sp + 1) / 10000;
29642 5 int32_t startpos = SH::read_stack(ri->sp);
29643
29644
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (arrayptr == 0)
29645 {
29646 bool ret = play_enh_music_crossfade(NULL, qstpath, track, get_emusic_volume(), fadeoutframes, fadeinframes, fademiddleframes, startpos);
29647 ri->d[rEXP1] = ret ? 10000 : 0;
29648 }
29649 else
29650 {
29651 5 string filename_str;
29652 char filename_char[256];
29653
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 ArrayH::getString(arrayptr, filename_str, 256);
29654 5 strncpy(filename_char, filename_str.c_str(), 255);
29655 5 filename_char[255] = '\0';
29656
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 bool ret = play_enh_music_crossfade(filename_char, qstpath, track, get_emusic_volume(), fadeoutframes, fadeinframes, fademiddleframes, startpos, true);
29657 5 ri->d[rEXP1] = ret ? 10000 : 0;
29658 5 }
29659 5 }
29660
29661 bool FFScript::doing_dmap_enh_music(int32_t dm)
29662 {
29663 if (DMaps[dm].tmusic[0] != 0)
29664 {
29665 if (zcmusic != NULL)
29666 {
29667 if (strcmp(zcmusic->filename, DMaps[dm].tmusic) == 0)
29668 {
29669 switch (zcmusic_get_type(zcmusic))
29670 {
29671 case ZCMF_OGG:
29672 case ZCMF_MP3:
29673 return true;
29674 case ZCMF_DUH:
29675 case ZCMF_GME:
29676 if (zcmusic->track == DMaps[dm].tmusictrack)
29677 {
29678 return true;
29679 }
29680 }
29681 }
29682 }
29683 }
29684 return false;
29685 }
29686
29687 38274 bool FFScript::can_dmap_change_music(int32_t dm)
29688 {
29689
1/4
✓ Branch 0 taken 38274 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
38274 switch (music_update_cond)
29690 {
29691 case MUSIC_UPDATE_SCREEN:
29692 38274 return true;
29693 case MUSIC_UPDATE_DMAP:
29694 return dm != -1 && dm != cur_dmap;
29695 case MUSIC_UPDATE_LEVEL:
29696 return dm != -1 && DMaps[dm].level != DMaps[cur_dmap].level;
29697 }
29698 return false;
29699 38274 }
29700
29701 void FFScript::do_set_music_position(const bool v)
29702 {
29703 int32_t newposition = SH::get_arg(sarg1, v);
29704
29705 set_zcmusicpos(newposition);
29706 }
29707
29708 void FFScript::do_get_music_position()
29709 {
29710 int32_t pos = replay_get_state(ReplayStateType::MusicPosition, [](){
29711 return zcmusic_get_curpos(zcmusic);
29712 });
29713 set_register(sarg1, pos);
29714 }
29715
29716 void FFScript::do_set_music_speed(const bool v)
29717 {
29718 int32_t newspeed = SH::get_arg(sarg1, v);
29719 set_zcmusicspeed(newspeed);
29720 }
29721
29722 void FFScript::do_get_music_length()
29723 {
29724 int32_t len = get_zcmusiclen();
29725 set_register(sarg1, len);
29726 }
29727
29728 3 void FFScript::do_set_music_loop()
29729 {
29730 3 double start = (get_register(sarg1) / 10000.0);
29731 3 double end = (get_register(sarg2) / 10000.0);
29732
29733 3 set_zcmusicloop(start, end);
29734 3 }
29735
29736 236 void do_get_enh_music_filename(const bool v)
29737 {
29738 236 int32_t ID = SH::get_arg(sarg1, v) / 10000;
29739 236 int32_t arrayptr = get_register(sarg2) / 10000;
29740
29741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 236 times.
236 if(BC::checkDMapID(ID) != SH::_NoError)
29742 return;
29743
29744
3/6
✓ Branch 0 taken 236 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 236 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 236 times.
✗ Branch 5 not taken.
236 if(ArrayH::setArray(arrayptr, string(DMaps[ID].tmusic)) == SH::_Overflow)
29745 Z_scripterrlog("Array supplied to 'Game->GetDMapMusicFilename' not large enough\n");
29746 236 }
29747
29748 140 void do_get_enh_music_track(const bool v)
29749 {
29750 140 int32_t ID = SH::get_arg(sarg1, v) / 10000;
29751
29752
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 132 times.
140 if(BC::checkDMapID(ID) != SH::_NoError)
29753 8 return;
29754
29755 132 set_register(sarg1, (DMaps[ID].tmusictrack+1)*10000);
29756 140 }
29757
29758 3783 void do_set_dmap_enh_music(const bool v)
29759 {
29760 3783 int32_t ID = SH::read_stack(ri->sp + 2) / 10000;
29761 3783 int32_t arrayptr = SH::read_stack(ri->sp + 1) / 10000;
29762 3783 int32_t track = (SH::read_stack(ri->sp + 0) / 10000)-1;
29763 3783 string filename_str;
29764
29765
2/4
✓ Branch 0 taken 3783 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3783 times.
✗ Branch 3 not taken.
3783 if(BC::checkDMapID(ID) != SH::_NoError)
29766 return;
29767
29768
1/2
✓ Branch 0 taken 3783 times.
✗ Branch 1 not taken.
3783 ArrayH::getString(arrayptr, filename_str, 56);
29769 3783 strncpy(DMaps[ID].tmusic, filename_str.c_str(), 55);
29770 3783 DMaps[ID].tmusic[55]='\0';
29771 3783 DMaps[ID].tmusictrack=track;
29772
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3783 times.
3783 }
29773
29774
29775
29776
29777
29778
29779 ///----------------------------------------------------------------------------------------------------//
29780 //Array & string related
29781
29782 303067642 void do_arraysize()
29783 {
29784 303067642 int32_t arrayptr = get_register(sarg1) / 10000;
29785 303067642 ri->d[rEXP1] = ArrayH::getSize(arrayptr) * 10000;
29786 303067642 }
29787
29788 void do_tobyte()
29789 {
29790 int32_t b1 = get_register(sarg1) / 10000;
29791 byte b2 = b1;
29792 set_register(sarg1, b2 * 10000);
29793 }
29794
29795 void do_tosignedbyte()
29796 {
29797 int32_t b1 = get_register(sarg1) / 10000;
29798 signed char b2 = b1;
29799 set_register(sarg1, b2 * 10000);
29800 }
29801
29802 void do_tointeger()
29803 {
29804 int32_t b1 = get_register(sarg1) / 10000;
29805 set_register(sarg1, b1 * 10000);
29806 }
29807
29808 7 void do_floor()
29809 {
29810 7 set_register(sarg1, zslongToFix(get_register(sarg1)).doFloor().getZLong());
29811 7 }
29812
29813 void do_trunc()
29814 {
29815 set_register(sarg1, zslongToFix(get_register(sarg1)).doTrunc().getZLong());
29816 }
29817
29818 void do_ceiling()
29819 {
29820 set_register(sarg1, zslongToFix(get_register(sarg1)).doCeil().getZLong());
29821 }
29822
29823 void do_round()
29824 {
29825 set_register(sarg1, zslongToFix(get_register(sarg1)).doRound().getZLong());
29826 }
29827
29828 void do_roundaway()
29829 {
29830 set_register(sarg1, zslongToFix(get_register(sarg1)).doRoundAway().getZLong());
29831 }
29832
29833 void do_toword()
29834 {
29835 int32_t b1 = get_register(sarg1) / 10000;
29836 word b2 = b1;
29837 set_register(sarg1, b2 * 10000);
29838 }
29839
29840 void do_toshort()
29841 {
29842 int32_t b1 = get_register(sarg1) / 10000;
29843 int16_t b2 = b1;
29844 set_register(sarg1, b2 * 10000);
29845 }
29846
29847 //Set npc and item names t.b.a. -Z
29848
29849 2768 void do_getitemname()
29850 {
29851 2768 int32_t arrayptr = get_register(sarg1) / 10000;
29852
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2768 times.
2768 if(unsigned(ri->idata) >= MAXITEMS)
29853 {
29854 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
29855 return;
29856 }
29857
29858
3/6
✓ Branch 0 taken 2768 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2768 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2768 times.
✗ Branch 5 not taken.
2768 if(ArrayH::setArray(arrayptr, item_string[ri->idata]) == SH::_Overflow)
29859 Z_scripterrlog("Array supplied to 'itemdata->GetName' not large enough\n");
29860 2768 }
29861
29862 10105619 void do_getffcscript()
29863 {
29864 10105619 do_get_script_index_by_name(name_to_slot_index_ffcmap);
29865 10105619 }
29866
29867 80 void do_getitemscript()
29868 {
29869 80 do_get_script_index_by_name(name_to_slot_index_itemmap);
29870 80 }
29871
29872 ///----------------------------------------------------------------------------------------------------//
29873 //Tile Manipulation
29874
29875 49233778 void do_copytile(const bool v, const bool v2)
29876 {
29877 49233778 int32_t tile = SH::get_arg(sarg1, v) / 10000;
29878 49233778 int32_t tile2 = SH::get_arg(sarg2, v2) / 10000;
29879
29880 49233778 copy_tile(newtilebuf, tile, tile2, false);
29881 49233778 }
29882
29883 int32_t FFScript::IsBlankTile(int32_t i)
29884 {
29885 if( ((unsigned)i) > NEWMAXTILES )
29886 {
29887 Z_scripterrlog("Invalid tile ID (%d) passed to Graphics->IsBlankTile[]\n");
29888 return -1;
29889 }
29890
29891 byte *tilestart=newtilebuf[i].data;
29892 qword *di=(qword*)tilestart;
29893 int32_t parts=tilesize(newtilebuf[i].format)>>3;
29894
29895 for(int32_t j=0; j<parts; ++j, ++di)
29896 {
29897 if(*di!=0)
29898 {
29899 return 0;
29900 }
29901 }
29902
29903 return 1;
29904 }
29905
29906 int32_t FFScript::Is8BitTile(int32_t i)
29907 {
29908 if (((unsigned)i) > NEWMAXTILES)
29909 {
29910 Z_scripterrlog("Invalid tile ID (%d) passed to Graphics->Is8BitTile[]\n");
29911 return -1;
29912 }
29913
29914 return newtilebuf[i].format == tf8Bit ? 1 : 0;
29915 }
29916
29917 void do_swaptile(const bool v, const bool v2)
29918 {
29919 int32_t tile = SH::get_arg(sarg1, v) / 10000;
29920 int32_t tile2 = SH::get_arg(sarg2, v2) / 10000;
29921
29922 copy_tile(newtilebuf, tile, tile2, true);
29923 }
29924
29925 57032 void do_overlaytile(const bool v, const bool v2)
29926 {
29927 57032 int32_t tile = SH::get_arg(sarg1, v) / 10000;
29928 57032 int32_t tile2 = SH::get_arg(sarg2, v2) / 10000;
29929
29930
2/4
✓ Branch 0 taken 57032 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57032 times.
✗ Branch 3 not taken.
57032 if(BC::checkTile(tile) != SH::_NoError ||
29931 57032 BC::checkTile(tile2) != SH::_NoError)
29932 return;
29933
29934 //Could add an arg for the CSet or something instead of just passing 0, currently only 8-bit is supported
29935 57032 overlay_tile(newtilebuf, tile, tile2, 0, false);
29936 57032 }
29937
29938 void do_fliprotatetile(const bool v, const bool v2)
29939 {
29940 int32_t tile = SH::get_arg(sarg1, v) / 10000;
29941 int32_t tile2 = SH::get_arg(sarg2, v2) / 10000;
29942
29943 if(BC::checkTile(tile) != SH::_NoError ||
29944 BC::checkTile(tile2) != SH::_NoError)
29945 return;
29946
29947 //fliprotatetile
29948 }
29949
29950 void do_settilepixel()
29951 {
29952 int32_t tile = SH::read_stack(ri->sp + 3) / 10000;
29953 int32_t x = SH::read_stack(ri->sp + 2) / 10000;
29954 int32_t y = SH::read_stack(ri->sp + 1) / 10000;
29955 int32_t val = SH::read_stack(ri->sp + 0) / 10000;
29956
29957 if(BC::checkTile(tile) != SH::_NoError)
29958 return;
29959
29960 x = vbound(x, 0, 15);
29961 y = vbound(y, 0, 15);
29962 unpack_tile(newtilebuf, tile, 0, false);
29963 if (newtilebuf[tile].format == tf4Bit)
29964 val &= 0xF;
29965 unpackbuf[y * 16 + x] = val;
29966 pack_tile(newtilebuf, unpackbuf, tile);
29967 }
29968
29969 void do_gettilepixel()
29970 {
29971 int32_t tile = SH::read_stack(ri->sp + 3) / 10000;
29972 int32_t x = SH::read_stack(ri->sp + 2) / 10000;
29973 int32_t y = SH::read_stack(ri->sp + 1) / 10000;
29974 int32_t cs = SH::read_stack(ri->sp + 0) / 10000;
29975
29976 if(BC::checkTile(tile) != SH::_NoError)
29977 return;
29978
29979 x = vbound(x, 0, 15);
29980 y = vbound(y, 0, 15);
29981 unpack_tile(newtilebuf, tile, 0, false);
29982 int32_t csoffs = newtilebuf[tile].format == tf8Bit ? 0 : cs * 16;
29983 ri->d[rEXP1] = 10000 * (unpackbuf[y * 16 + x] + csoffs);
29984 }
29985
29986 void do_shifttile(const bool v, const bool v2)
29987 {
29988 int32_t tile = SH::get_arg(sarg1, v) / 10000;
29989 int32_t tile2 = SH::get_arg(sarg2, v2) / 10000;
29990
29991 if(BC::checkTile(tile) != SH::_NoError ||
29992 BC::checkTile(tile2) != SH::_NoError)
29993 return;
29994
29995 //shifttile
29996 }
29997
29998 10 void do_cleartile(const bool v)
29999 {
30000 10 int32_t tile = SH::get_arg(sarg1, v) / 10000;
30001
30002
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(BC::checkTile(tile) != SH::_NoError)
30003 return;
30004
30005 10 reset_tile(newtilebuf, tile, newtilebuf[tile].format);
30006 10 }
30007
30008 3062 void do_combotile(const bool v)
30009 {
30010 3062 int32_t combo = SH::get_arg(sarg2, v) / 10000;
30011
30012
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3062 times.
3062 if(BC::checkCombo(combo) != SH::_NoError)
30013 return;
30014
30015 3062 set_register(sarg1, combobuf[combo].tile * 10000);
30016 3062 }
30017
30018 232893622 void do_readpod(const bool v)
30019 {
30020 232893622 int32_t indx = SH::get_arg(sarg2, v) / 10000;
30021 232893622 int32_t val = ArrayH::getElement(ri->d[rINDEX] / 10000, indx, can_neg_array);
30022 232893622 set_register(sarg1, val);
30023 232893622 }
30024 134165112 void do_writepod(const bool v1, const bool v2)
30025 {
30026 134165112 int32_t indx = SH::get_arg(sarg1, v1) / 10000;
30027 134165112 int32_t val = SH::get_arg(sarg2, v2);
30028 134165112 ArrayH::setElement(ri->d[rINDEX] / 10000, indx, val, can_neg_array);
30029 134165112 }
30030 3239555 void do_writepodstr()
30031 {
30032
2/2
✓ Branch 0 taken 30325 times.
✓ Branch 1 taken 3209230 times.
3239555 if(!sargstr) return;
30033 3209230 auto ptr = get_register(sarg1) / 10000;
30034 3209230 ArrayH::setArray(ptr, *sargstr);
30035 3239555 }
30036 560107 void do_writepodarr()
30037 {
30038
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 560107 times.
560107 if(!sargvec) return;
30039 560107 auto ptr = get_register(sarg1) / 10000;
30040 560107 ArrayH::setArray(ptr, sargvec->size(), sargvec->data(), false);
30041 560107 }
30042
30043 // TODO: move somewhere else.
30044 156 void destroy_object_arr(int32_t ptr, bool dec_refs)
30045 {
30046
1/2
✓ Branch 0 taken 156 times.
✗ Branch 1 not taken.
156 if(ptr < 0)
30047 {
30048 156 auto it = objectRAM.find(-ptr);
30049
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 156 times.
156 if(it != objectRAM.end())
30050 {
30051 156 auto& aptr = it->second;
30052
3/4
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 144 times.
156 if (dec_refs && aptr.HoldsObjects())
30053 {
30054
2/2
✓ Branch 0 taken 520 times.
✓ Branch 1 taken 144 times.
664 for (int i = 0; i < aptr.Size(); i++)
30055 520 script_object_ref_dec(aptr[i]);
30056 144 }
30057 156 objectRAM.erase(it);
30058 156 }
30059 156 }
30060 156 }
30061
30062 int32_t get_own_i(ScriptType type)
30063 {
30064 switch(type)
30065 {
30066 case ScriptType::Lwpn:
30067 return ri->lwpn;
30068 case ScriptType::Ewpn:
30069 return ri->ewpn;
30070 case ScriptType::ItemSprite:
30071 return ri->itemref;
30072 case ScriptType::NPC:
30073 return ri->guyref;
30074 case ScriptType::FFC:
30075 if (auto ffc = ResolveFFC(ri->ffcref))
30076 return ffc->index;
30077 }
30078 return 0;
30079 }
30080
30081 portal* loadportal(savedportal& p);
30082
30083 ///----------------------------------------------------------------------------------------------------//
30084 // Run the script //
30085 ///----------------------------------------------------------------------------------------------------//
30086
30087 2947 static bool check_cmp(uint cmp)
30088 {
30089
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2947 times.
2947 if(cmp & CMP_BOOL)
30090 {
30091 if(ri->cmp_strcache) return false; //Cast string to bool? nonsense...
30092 switch(cmp & CMP_FLAGS)
30093 {
30094 case CMP_EQ:
30095 return !ri->cmp_op1 == !ri->cmp_op2;
30096 case CMP_NE:
30097 return !ri->cmp_op1 != !ri->cmp_op2;
30098 }
30099 return false;
30100 }
30101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2947 times.
2947 else if(ri->cmp_strcache)
30102 {
30103 if(*ri->cmp_strcache < 0)
30104 return (cmp & CMP_LT);
30105 if(*ri->cmp_strcache > 0)
30106 return (cmp & CMP_GT);
30107 return (cmp & CMP_EQ);
30108 }
30109 else
30110 {
30111
2/2
✓ Branch 0 taken 1511 times.
✓ Branch 1 taken 1436 times.
2947 if(cmp & CMP_GT)
30112
2/2
✓ Branch 0 taken 243 times.
✓ Branch 1 taken 1193 times.
1436 if(ri->cmp_op1 > ri->cmp_op2)
30113 243 return true;
30114
2/2
✓ Branch 0 taken 1746 times.
✓ Branch 1 taken 958 times.
2704 if(cmp & CMP_LT)
30115
2/2
✓ Branch 0 taken 909 times.
✓ Branch 1 taken 49 times.
958 if(ri->cmp_op1 < ri->cmp_op2)
30116 909 return true;
30117
2/2
✓ Branch 0 taken 615 times.
✓ Branch 1 taken 1180 times.
1795 if(cmp & CMP_EQ)
30118
2/2
✓ Branch 0 taken 582 times.
✓ Branch 1 taken 598 times.
1180 if(ri->cmp_op1 == ri->cmp_op2)
30119 582 return true;
30120 1213 return false;
30121 }
30122 2947 }
30123
30124 void goto_err(char const* opname)
30125 {
30126 auto i = curScriptIndex;
30127 const char* type_str = ScriptTypeToString(curScriptType);
30128 switch(curScriptType)
30129 {
30130 case ScriptType::FFC:
30131 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, ffcmap[i].scriptname.c_str(), opname, sarg1); break;
30132 case ScriptType::NPC:
30133 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, npcmap[i].scriptname.c_str(), opname, sarg1); break;
30134 case ScriptType::Lwpn:
30135 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, lwpnmap[i].scriptname.c_str(), opname, sarg1); break;
30136 case ScriptType::Ewpn:
30137 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, ewpnmap[i].scriptname.c_str(), opname, sarg1); break;
30138 case ScriptType::ItemSprite:
30139 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, itemspritemap[i].scriptname.c_str(), opname, sarg1); break;
30140 case ScriptType::Item:
30141 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, itemmap[i].scriptname.c_str(), opname, sarg1); break;
30142 case ScriptType::Global:
30143 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, globalmap[i].scriptname.c_str(), opname, sarg1); break;
30144 case ScriptType::Hero:
30145 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, playermap[i].scriptname.c_str(), opname, sarg1); break;
30146 case ScriptType::Screen:
30147 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, screenmap[i].scriptname.c_str(), opname, sarg1); break;
30148 case ScriptType::OnMap:
30149 case ScriptType::DMap:
30150 case ScriptType::ScriptedActiveSubscreen:
30151 case ScriptType::ScriptedPassiveSubscreen:
30152 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, dmapmap[i].scriptname.c_str(), opname, sarg1); break;
30153 case ScriptType::Combo:
30154 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, comboscriptmap[i].scriptname.c_str(), opname, sarg1); break;
30155
30156 default: break;
30157 }
30158 }
30159
30160 85470 static void script_exit_cleanup(bool no_dealloc)
30161 {
30162 85470 ScriptType type = curScriptType;
30163 85470 word script = curScriptNum;
30164 85470 int32_t i = curScriptIndex;
30165
30166
8/9
✓ Branch 0 taken 10515 times.
✓ Branch 1 taken 62522 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10210 times.
✓ Branch 4 taken 81 times.
✓ Branch 5 taken 49 times.
✓ Branch 6 taken 34 times.
✓ Branch 7 taken 10 times.
✓ Branch 8 taken 2049 times.
85470 switch(type)
30167 {
30168 case ScriptType::FFC:
30169 {
30170
1/2
✓ Branch 0 taken 10210 times.
✗ Branch 1 not taken.
10210 if (auto ffc = ResolveFFCWithID(i))
30171 10210 ffc->script = 0;
30172 10210 auto& data = get_script_engine_data(type, i);
30173 10210 data.doscript = false;
30174 }
30175 10210 break;
30176
30177 case ScriptType::Screen:
30178 81 get_scr(i)->script = 0;
30179 case ScriptType::Global:
30180 case ScriptType::Hero:
30181 case ScriptType::DMap:
30182 case ScriptType::OnMap:
30183 case ScriptType::ScriptedActiveSubscreen:
30184 case ScriptType::ScriptedPassiveSubscreen:
30185 case ScriptType::EngineSubscreen:
30186 case ScriptType::Combo:
30187 {
30188 10596 auto& data = get_script_engine_data(type, i);
30189 10596 data.doscript = false;
30190 }
30191 10596 break;
30192 case ScriptType::Ewpn:
30193 case ScriptType::Lwpn:
30194 case ScriptType::NPC:
30195 {
30196 62522 auto& data = get_script_engine_data(type, i);
30197 62522 data.doscript = false;
30198 62522 data.initialized = false;
30199
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62522 times.
62522 if (auto spr = sprite::getByUID(i))
30200 62522 spr->weaponscript = 0;
30201 }
30202 62522 break;
30203 case ScriptType::ItemSprite:
30204 {
30205 49 auto& data = get_script_engine_data(type, i);
30206 49 data.doscript = false;
30207 49 data.initialized = false;
30208
1/2
✓ Branch 0 taken 49 times.
✗ Branch 1 not taken.
49 if (auto spr = sprite::getByUID(i))
30209 49 spr->script = 0;
30210 }
30211 49 break;
30212
30213 case ScriptType::Generic:
30214 34 user_genscript::get(script).quit();
30215 34 break;
30216
30217 case ScriptType::GenericFrozen:
30218 10 FFCore.doscript(ScriptType::GenericFrozen, gen_frozen_index-1) = false;
30219 10 break;
30220
30221 case ScriptType::Item:
30222 {
30223
2/2
✓ Branch 0 taken 1742 times.
✓ Branch 1 taken 307 times.
2049 bool collect = ( ( i < 1 ) || (i == COLLECT_SCRIPT_ITEM_ZERO) );
30224
3/4
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 1742 times.
✓ Branch 2 taken 307 times.
✗ Branch 3 not taken.
2049 int new_i = ( collect ) ? (( i != COLLECT_SCRIPT_ITEM_ZERO ) ? (i * -1) : 0) : i;
30225 2049 auto& data = get_script_engine_data(ScriptType::Item, i);
30226
2/2
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 1742 times.
2049 if ( !collect )
30227 {
30228
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1742 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1742 if ( (itemsbuf[i].flags&item_passive_script) && game->item[i] ) itemsbuf[i].script = 0; //Quit perpetual scripts, too.
30229 1742 data.doscript = 0;
30230 1742 data.ref.Clear();
30231 1742 }
30232 else
30233 {
30234 307 data.doscript = 0;
30235 307 data.ref.Clear();
30236 }
30237 2049 data.initialized = false;
30238 2049 break;
30239 }
30240 }
30241
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 85470 times.
85470 if(!no_dealloc)
30242
2/2
✓ Branch 0 taken 83421 times.
✓ Branch 1 taken 2049 times.
85470 switch(type)
30243 {
30244 case ScriptType::Item:
30245 {
30246
2/2
✓ Branch 0 taken 1742 times.
✓ Branch 1 taken 307 times.
2049 bool collect = ( ( i < 1 ) || (i == COLLECT_SCRIPT_ITEM_ZERO) );
30247
3/4
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 1742 times.
✓ Branch 2 taken 307 times.
✗ Branch 3 not taken.
2049 int new_i = ( collect ) ? (( i != COLLECT_SCRIPT_ITEM_ZERO ) ? (i * -1) : 0) : i;
30248 2049 FFScript::deallocateAllScriptOwned(ScriptType::Item, new_i);
30249 2049 break;
30250 }
30251
30252 default:
30253 83421 FFScript::deallocateAllScriptOwned(type, i);
30254 83421 break;
30255 85470 }
30256 85470 }
30257
30258 30538924 int32_t run_script(ScriptType type, word script, int32_t i)
30259 {
30260
3/4
✓ Branch 0 taken 30538924 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 65 times.
✓ Branch 3 taken 30538859 times.
30538924 if(Quit==qRESET || Quit==qEXIT) // In case an earlier script hung
30261 65 return RUNSCRIPT_ERROR;
30262
30263
4/4
✓ Branch 0 taken 19426349 times.
✓ Branch 1 taken 11112510 times.
✓ Branch 2 taken 15556048 times.
✓ Branch 3 taken 3870301 times.
30538859 if(type != ScriptType::Global && !script) return RUNSCRIPT_OK; //Safeguard against running null scripts
30264
30265 26668558 combopos_modified = -1;
30266 26668558 curScriptType=type;
30267 26668558 curScriptNum=script;
30268 26668558 curScriptIndex=i;
30269 26668558 current_zasm_register=0;
30270 26668558 current_zasm_command=(ASM_DEFINE)0; // this is actually SETV, but we never will print that as a context string, so it's fine.
30271 //numInstructions=0; //DON'T CLEAR THIS OR IT CAN HARDLOCK! -Em
30272
30273
2/4
✓ Branch 0 taken 26668558 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 26668558 times.
26668558 if (!(type >= ScriptType::First && type <= ScriptType::Last))
30274 {
30275 al_trace("Invalid script type: %d\n", (int)type);
30276 return RUNSCRIPT_ERROR;
30277 }
30278
30279 26668558 bool got_initialized = false;
30280
1/2
✓ Branch 0 taken 26668558 times.
✗ Branch 1 not taken.
26668558 switch(type)
30281 {
30282 case ScriptType::FFC:
30283 case ScriptType::Global:
30284 case ScriptType::Hero:
30285 case ScriptType::DMap:
30286 case ScriptType::OnMap:
30287 case ScriptType::ScriptedActiveSubscreen:
30288 case ScriptType::ScriptedPassiveSubscreen:
30289 case ScriptType::EngineSubscreen:
30290 case ScriptType::Screen:
30291 case ScriptType::Combo:
30292 case ScriptType::Item:
30293 case ScriptType::NPC:
30294 case ScriptType::Lwpn:
30295 case ScriptType::Ewpn:
30296 case ScriptType::ItemSprite:
30297 case ScriptType::Generic:
30298 case ScriptType::GenericFrozen:
30299 {
30300 26668558 got_initialized = set_current_script_engine_data(type, script, i);
30301 }
30302 26668558 break;
30303
30304 default:
30305 {
30306 al_trace("No other scripts are currently supported\n");
30307 return RUNSCRIPT_ERROR;
30308 }
30309 }
30310
30311 // Because qst.cpp likes to write script_data without setting this.
30312 26668558 curscript->meta.script_type = type;
30313
30314 // If script isn't valid, we don't have a `pc` to start from... just exit.
30315
2/2
✓ Branch 0 taken 26665816 times.
✓ Branch 1 taken 2742 times.
26668558 if(!curscript->valid())
30316 {
30317 2742 script_exit_cleanup(false);
30318 2742 return RUNSCRIPT_OK;
30319 }
30320
30321 26665816 script_funcrun = false;
30322
30323 26665816 JittedScriptHandle* jitted_script = nullptr;
30324
2/2
✓ Branch 0 taken 26665812 times.
✓ Branch 1 taken 4 times.
26665816 if (jit_is_enabled())
30325 {
30326 26665812 auto key = std::make_pair(curscript, ri);
30327 26665812 auto it = jitted_scripts.find(key);
30328
2/2
✓ Branch 0 taken 78570 times.
✓ Branch 1 taken 26587242 times.
26665812 if (it == jitted_scripts.end())
30329 {
30330 78570 jitted_scripts[key] = jitted_script = jit_create_script_handle(curscript, ri);
30331 78570 }
30332 else
30333 {
30334 26587242 jitted_script = it->second;
30335 }
30336 26665812 }
30337
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
4 else if (zasm_optimize_enabled() && curscript->valid() && !curscript->zasm_script->optimized)
30338 {
30339 zasm_optimize_and_log(curscript->zasm_script.get());
30340 }
30341
30342 26665816 runtime_script_debug_handle = nullptr;
30343
1/2
✓ Branch 0 taken 26665816 times.
✗ Branch 1 not taken.
26665816 if (script_debug_is_runtime_debugging())
30344 {
30345 if (!script_debug_handles.contains(curscript->id))
30346 {
30347 script_debug_handles.emplace(curscript->id, ScriptDebugHandle(
30348 curscript->zasm_script.get(), ScriptDebugHandle::OutputSplit::ByFrame, curscript->name()));
30349 }
30350 runtime_script_debug_handle = &script_debug_handles.at(curscript->id);
30351 runtime_script_debug_handle->update_file();
30352 std::string line = fmt::format("=== running script type: {} index: {} name: {} i: {} script: {}", ScriptTypeToString(curscript->id.type), curscript->id.index, curscript->meta.script_name, i, script);
30353 runtime_script_debug_handle->print("\n");
30354 runtime_script_debug_handle->print(line.c_str());
30355 runtime_script_debug_handle->print("\n");
30356
30357 replay_step_comment(line);
30358 }
30359
1/2
✓ Branch 0 taken 26665816 times.
✗ Branch 1 not taken.
26665816 if (script_debug_is_runtime_debugging() == 1)
30360 {
30361 std::string line = script_debug_registers_and_stack_to_string();
30362 runtime_script_debug_handle->print(line.c_str());
30363 runtime_script_debug_handle->print("\n");
30364
30365 util::replchar(line, '\n', ' ');
30366 replay_step_comment(line);
30367 }
30368
30369 int32_t result;
30370
2/2
✓ Branch 0 taken 26665809 times.
✓ Branch 1 taken 7 times.
26665816 if (jitted_script)
30371 {
30372
2/2
✓ Branch 0 taken 26562847 times.
✓ Branch 1 taken 102962 times.
26665809 if (got_initialized)
30373 102962 jit_reinit(jitted_script);
30374
2/2
✓ Branch 0 taken 30148 times.
✓ Branch 1 taken 26635661 times.
26665809 if (ri->waitframes)
30375 {
30376 30148 --ri->waitframes;
30377 30148 result = RUNSCRIPT_OK;
30378 30148 }
30379 else
30380 {
30381 26635661 result = jit_run_script(jitted_script);
30382 }
30383 26665809 }
30384 else
30385 {
30386 7 result = run_script_int(false);
30387 }
30388
30389
2/2
✓ Branch 0 taken 24306354 times.
✓ Branch 1 taken 2359462 times.
26665816 if (ZScriptVersion::gc())
30390 {
30391 // Drain the autorelease pool.
30392 // Move the vector, since destructors can possibly
30393 // create objects and modify `script_object_autorelease_pool`.
30394 2359462 auto ids = std::move(script_object_autorelease_pool);
30395
2/2
✓ Branch 0 taken 2359462 times.
✓ Branch 1 taken 228 times.
2359690 for (auto id : ids)
30396
1/2
✓ Branch 0 taken 228 times.
✗ Branch 1 not taken.
228 script_object_ref_dec(id);
30397
30398 // This throttles the actual full GC run.
30399
1/2
✓ Branch 0 taken 2359462 times.
✗ Branch 1 not taken.
2359462 maybe_run_gc();
30400 2359462 }
30401
30402
6/16
✗ Branch 0 not taken.
✓ Branch 1 taken 26665816 times.
✓ Branch 2 taken 26665816 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 26665816 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 26665816 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 26665816 times.
✓ Branch 10 taken 26665816 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
53331632 if (replay_is_active() && replay_get_meta_bool("debug_script_state"))
30403 {
30404 std::string str = script_debug_registers_and_stack_to_string();
30405 util::replstr(str, "\n", " ");
30406 replay_step_comment(str);
30407 }
30408
30409
1/2
✓ Branch 0 taken 26665816 times.
✗ Branch 1 not taken.
26665816 if (runtime_script_debug_handle)
30410 {
30411 runtime_script_debug_handle->print(fmt::format("result: {}\n", result).c_str());
30412 replay_step_comment(fmt::format("result: {}", result));
30413 }
30414 26665816 return result;
30415 30538924 }
30416
30417 1165699795 int32_t run_script_int(bool is_jitted)
30418 {
30419 1165699795 ScriptType type = curScriptType;
30420 1165699795 word script = curScriptNum;
30421 1165699795 int32_t i = curScriptIndex;
30422
30423 1165699795 int commands_run = 0;
30424 1165699795 int jit_waiting_nop = false;
30425
2/2
✓ Branch 0 taken 1165699675 times.
✓ Branch 1 taken 120 times.
1165699795 bool old_script_funcrun = script_funcrun && curscript->meta.ffscript_v < 23;
30426
2/2
✓ Branch 0 taken 1165699668 times.
✓ Branch 1 taken 127 times.
1165699795 if(!is_jitted)
30427 {
30428
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127 times.
127 if(ri->waitframes)
30429 {
30430 --ri->waitframes;
30431 return RUNSCRIPT_OK;
30432 }
30433 127 zs_vargs.clear();
30434
30435 #ifdef _FFDISSASSEMBLY
30436
30437 if(curscript->zasm[ri->pc].command != 0xFFFF)
30438 {
30439 #ifdef _FFONESCRIPTDISSASSEMBLY
30440 zc_trace_clear();
30441 #endif
30442
30443 switch(type)
30444 {
30445 case ScriptType::FFC:
30446 al_trace("\nStart of FFC script %i processing on FFC %i:\n", script, i);
30447 break;
30448
30449 case ScriptType::Item:
30450 al_trace("\nStart of item script %i processing:\n", script);
30451 break;
30452
30453 case ScriptType::Global:
30454 al_trace("\nStart of global script %I processing:\n", script);
30455 break;
30456 }
30457 }
30458
30459 #endif
30460 127 }
30461 //j_command
30462 1165699795 bool is_debugging = script_debug_is_runtime_debugging() == 2;
30463 1165699795 bool increment = true;
30464
5/8
✓ Branch 0 taken 218 times.
✓ Branch 1 taken 1165699577 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 218 times.
✓ Branch 4 taken 218 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 218 times.
✗ Branch 7 not taken.
1165699795 static std::vector<ffscript> empty_zasm = {{0xFFFF}};
30465
1/2
✓ Branch 0 taken 1165699795 times.
✗ Branch 1 not taken.
1165699795 const auto& zasm = curscript->valid() ? curscript->zasm_script->zasm : empty_zasm;
30466 1165699795 word scommand = zasm[ri->pc].command;
30467 1165699795 bool hit_invalid_zasm = false;
30468 1165699795 bool no_dealloc = false;
30469
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 1174337491 times.
1174337643 while(scommand != 0xFFFF)
30470 {
30471 1174337491 const auto& op = zasm[ri->pc];
30472 1174337491 scommand = op.command;
30473 1174337491 sarg1 = op.arg1;
30474 1174337491 sarg2 = op.arg2;
30475 1174337491 sarg3 = op.arg3;
30476 1174337491 sargstr = op.strptr;
30477 1174337491 sargvec = op.vecptr;
30478
30479 1174337491 current_zasm_command = (ASM_DEFINE)op.command;
30480
30481
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1174337491 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1174337491 if (is_debugging && (!is_jitted || commands_run > 0))
30482 {
30483 runtime_script_debug_handle->pre_command();
30484 }
30485
30486 1174337491 bool waiting = true;
30487
6/6
✓ Branch 0 taken 1147783878 times.
✓ Branch 1 taken 6048065 times.
✓ Branch 2 taken 977482 times.
✓ Branch 3 taken 3138 times.
✓ Branch 4 taken 19522885 times.
✓ Branch 5 taken 2043 times.
1174337491 switch(scommand) //Handle waitframe-type commands first
30488 {
30489 case WAITDRAW:
30490 {
30491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6048065 times.
6048065 if(script_funcrun)
30492 scommand = NOP;
30493
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 6048065 times.
✗ Branch 2 not taken.
6048065 else switch(type)
30494 {
30495 case ScriptType::EngineSubscreen: //ignore waitdraws
30496 Z_scripterrlog("'Waitdraw()' is invalid in subscreen scripts, will be ignored\n");
30497 scommand = NOP;
30498 break;
30499 case ScriptType::Generic:
30500 case ScriptType::GenericFrozen: //ignore waitdraws
30501 Z_scripterrlog("'Waitdraw()' is invalid in generic scripts, will be ignored\n");
30502 scommand = NOP;
30503 break;
30504 }
30505 6048065 break;
30506 }
30507 case WAITTO:
30508 {
30509
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 977482 times.
977482 if(script_funcrun)
30510 scommand = NOP;
30511
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 977482 times.
977482 else switch(type)
30512 {
30513 case ScriptType::GenericFrozen:
30514 //ignore, no warn/error
30515 scommand = NOP;
30516 break;
30517 case ScriptType::Generic:
30518 {
30519 977482 user_genscript& scr = user_genscript::get(script);
30520 977482 int32_t target = get_register(sarg1)/10000L;
30521 977482 bool atleast = get_register(sarg2)!=0;
30522
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 977482 times.
977482 if(unsigned(target) > SCR_TIMING_END_FRAME)
30523 {
30524 Z_scripterrlog("Invalid value '%d' provided to 'WaitTo()'\n", target);
30525 scommand = NOP;
30526 break;
30527 }
30528
2/4
✓ Branch 0 taken 977481 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
977482 if(genscript_timing == target ||
30529
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 977481 times.
977481 (atleast && genscript_timing < target))
30530 {
30531 //Already that time, skip the command
30532 1 scommand = NOP;
30533 1 break;
30534 }
30535 977481 scr.waituntil = scr_timing(target);
30536 977481 scr.wait_atleast = atleast;
30537 977481 break;
30538 }
30539 default:
30540 Z_scripterrlog("'WaitTo()' is only valid in 'generic' scripts!\n");
30541 scommand = NOP;
30542 break;
30543 }
30544 977482 break;
30545 }
30546 case WAITEVENT:
30547 {
30548
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3138 times.
3138 if(script_funcrun)
30549 scommand = NOP;
30550
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 3138 times.
3138 else switch(type)
30551 {
30552 case ScriptType::GenericFrozen:
30553 scommand = WAITFRAME;
30554 ri->d[0] = GENSCR_EVENT_NIL*10000; //no event
30555 break;
30556 case ScriptType::Generic:
30557 {
30558 3138 user_genscript& scr = user_genscript::get(script);
30559 3138 scr.waitevent = true;
30560 3138 break;
30561 }
30562 default:
30563 Z_scripterrlog("'WaitEvent()' is only valid in 'generic' scripts!\n");
30564 scommand = NOP;
30565 break;
30566 }
30567 3138 break;
30568 }
30569 case WAITFRAME:
30570 {
30571
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19522885 times.
19522885 if(script_funcrun)
30572 scommand = NOP;
30573
2/2
✓ Branch 0 taken 18364950 times.
✓ Branch 1 taken 1157935 times.
19522885 else switch(type)
30574 {
30575 case ScriptType::Generic:
30576 {
30577 1157935 user_genscript& scr = user_genscript::get(script);
30578 1157935 scr.waituntil = SCR_TIMING_START_FRAME;
30579 1157935 scr.wait_atleast = false;
30580 1157935 break;
30581 }
30582 }
30583 19522885 break;
30584 }
30585 case WAITFRAMESR:
30586 {
30587 2043 auto count = get_register(sarg1);
30588
3/4
✓ Branch 0 taken 2043 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 690 times.
✓ Branch 3 taken 1353 times.
2043 if(script_funcrun || count <= 0)
30589 {
30590 690 scommand = NOP;
30591 690 break;
30592 }
30593 1353 auto frames = count/10000;
30594
1/2
✓ Branch 0 taken 1353 times.
✗ Branch 1 not taken.
1353 if(count%10000) ++frames; //round up decimals
30595 1353 ri->waitframes = frames-1; //this frame doesn't count
30596
2/2
✓ Branch 0 taken 1054 times.
✓ Branch 1 taken 299 times.
1353 switch(type)
30597 {
30598 case ScriptType::Generic:
30599 {
30600 299 user_genscript& scr = user_genscript::get(script);
30601 299 scr.waituntil = SCR_TIMING_START_FRAME;
30602 299 scr.wait_atleast = false;
30603 299 break;
30604 }
30605 }
30606 1353 break;
30607 }
30608 1147783878 default: waiting = false;
30609 1147783878 }
30610
4/4
✓ Branch 0 taken 26553613 times.
✓ Branch 1 taken 1147783878 times.
✓ Branch 2 taken 26552922 times.
✓ Branch 3 taken 691 times.
1174337491 if(waiting && scommand != NOP)
30611 {
30612
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26552922 times.
26552922 if (is_jitted)
30613 26552922 jit_waiting_nop = true;
30614 26552922 break;
30615 }
30616
30617 1147784569 numInstructions++;
30618
2/2
✓ Branch 0 taken 1146636860 times.
✓ Branch 1 taken 1147709 times.
1147784569 if(numInstructions==hangcount) // No need to check frequently
30619 {
30620 1147709 numInstructions=0;
30621 1147709 poll_keyboard();
30622 1147709 checkQuitKeys();
30623
1/2
✓ Branch 0 taken 1147709 times.
✗ Branch 1 not taken.
1147709 if(Quit)
30624 scommand=0xFFFF;
30625 1147709 }
30626
30627
244/878
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 151434482 times.
✓ Branch 10 taken 81459140 times.
✓ Branch 11 taken 50481826 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 80754051 times.
✓ Branch 14 taken 2929235 times.
✓ Branch 15 taken 3239555 times.
✓ Branch 16 taken 560107 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 603 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 1410 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✓ Branch 23 taken 2448 times.
✓ Branch 24 taken 4382 times.
✓ Branch 25 taken 1454 times.
✗ Branch 26 not taken.
✓ Branch 27 taken 28 times.
✓ Branch 28 taken 5548 times.
✓ Branch 29 taken 25 times.
✓ Branch 30 taken 50 times.
✗ Branch 31 not taken.
✓ Branch 32 taken 6044 times.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 37 taken 2959 times.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✓ Branch 40 taken 13741280 times.
✓ Branch 41 taken 10 times.
✗ Branch 42 not taken.
✓ Branch 43 taken 10105619 times.
✓ Branch 44 taken 80 times.
✓ Branch 45 taken 4 times.
✓ Branch 46 taken 987 times.
✓ Branch 47 taken 1714 times.
✓ Branch 48 taken 114 times.
✓ Branch 49 taken 6 times.
✓ Branch 50 taken 432 times.
✗ Branch 51 not taken.
✓ Branch 52 taken 564 times.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✓ Branch 55 taken 7 times.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✓ Branch 58 taken 415 times.
✗ Branch 59 not taken.
✓ Branch 60 taken 9550421 times.
✗ Branch 61 not taken.
✓ Branch 62 taken 6483138 times.
✗ Branch 63 not taken.
✓ Branch 64 taken 100 times.
✓ Branch 65 taken 1480 times.
✓ Branch 66 taken 138537 times.
✓ Branch 67 taken 6048 times.
✓ Branch 68 taken 14918 times.
✗ Branch 69 not taken.
✓ Branch 70 taken 5879938 times.
✓ Branch 71 taken 6352 times.
✓ Branch 72 taken 17821 times.
✓ Branch 73 taken 37547 times.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✓ Branch 76 taken 499288 times.
✓ Branch 77 taken 2541 times.
✗ Branch 78 not taken.
✓ Branch 79 taken 2925 times.
✓ Branch 80 taken 1 times.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✓ Branch 90 taken 14 times.
✓ Branch 91 taken 4797 times.
✓ Branch 92 taken 56 times.
✓ Branch 93 taken 935 times.
✗ Branch 94 not taken.
✗ Branch 95 not taken.
✗ Branch 96 not taken.
✗ Branch 97 not taken.
✗ Branch 98 not taken.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✓ Branch 101 taken 1 times.
✗ Branch 102 not taken.
✗ Branch 103 not taken.
✗ Branch 104 not taken.
✓ Branch 105 taken 1707 times.
✓ Branch 106 taken 1664 times.
✓ Branch 107 taken 137106 times.
✗ Branch 108 not taken.
✗ Branch 109 not taken.
✓ Branch 110 taken 31 times.
✗ Branch 111 not taken.
✗ Branch 112 not taken.
✗ Branch 113 not taken.
✗ Branch 114 not taken.
✗ Branch 115 not taken.
✗ Branch 116 not taken.
✗ Branch 117 not taken.
✗ Branch 118 not taken.
✗ Branch 119 not taken.
✗ Branch 120 not taken.
✓ Branch 121 taken 1520226 times.
✓ Branch 122 taken 5 times.
✓ Branch 123 taken 1649928 times.
✓ Branch 124 taken 1731172 times.
✗ Branch 125 not taken.
✗ Branch 126 not taken.
✗ Branch 127 not taken.
✗ Branch 128 not taken.
✓ Branch 129 taken 15 times.
✗ Branch 130 not taken.
✗ Branch 131 not taken.
✓ Branch 132 taken 10089782 times.
✗ Branch 133 not taken.
✗ Branch 134 not taken.
✗ Branch 135 not taken.
✗ Branch 136 not taken.
✗ Branch 137 not taken.
✗ Branch 138 not taken.
✓ Branch 139 taken 969 times.
✓ Branch 140 taken 648 times.
✓ Branch 141 taken 1 times.
✗ Branch 142 not taken.
✓ Branch 143 taken 8299299 times.
✓ Branch 144 taken 1137746 times.
✓ Branch 145 taken 678025 times.
✓ Branch 146 taken 243283 times.
✗ Branch 147 not taken.
✗ Branch 148 not taken.
✗ Branch 149 not taken.
✗ Branch 150 not taken.
✗ Branch 151 not taken.
✗ Branch 152 not taken.
✓ Branch 153 taken 3709786 times.
✓ Branch 154 taken 73964923 times.
✓ Branch 155 taken 2751879 times.
✓ Branch 156 taken 26716589 times.
✓ Branch 157 taken 4677945 times.
✓ Branch 158 taken 34306 times.
✓ Branch 159 taken 10744 times.
✓ Branch 160 taken 17 times.
✗ Branch 161 not taken.
✗ Branch 162 not taken.
✗ Branch 163 not taken.
✗ Branch 164 not taken.
✓ Branch 165 taken 22 times.
✗ Branch 166 not taken.
✓ Branch 167 taken 34296 times.
✗ Branch 168 not taken.
✓ Branch 169 taken 10283 times.
✗ Branch 170 not taken.
✓ Branch 171 taken 34 times.
✗ Branch 172 not taken.
✗ Branch 173 not taken.
✗ Branch 174 not taken.
✗ Branch 175 not taken.
✗ Branch 176 not taken.
✗ Branch 177 not taken.
✗ Branch 178 not taken.
✗ Branch 179 not taken.
✗ Branch 180 not taken.
✗ Branch 181 not taken.
✗ Branch 182 not taken.
✓ Branch 183 taken 2 times.
✓ Branch 184 taken 1361 times.
✓ Branch 185 taken 287 times.
✓ Branch 186 taken 11645 times.
✓ Branch 187 taken 33469 times.
✓ Branch 188 taken 319 times.
✗ Branch 189 not taken.
✓ Branch 190 taken 2 times.
✓ Branch 191 taken 2 times.
✗ Branch 192 not taken.
✗ Branch 193 not taken.
✗ Branch 194 not taken.
✗ Branch 195 not taken.
✓ Branch 196 taken 5660 times.
✗ Branch 197 not taken.
✓ Branch 198 taken 5436 times.
✗ Branch 199 not taken.
✗ Branch 200 not taken.
✓ Branch 201 taken 339164 times.
✗ Branch 202 not taken.
✗ Branch 203 not taken.
✗ Branch 204 not taken.
✗ Branch 205 not taken.
✗ Branch 206 not taken.
✓ Branch 207 taken 63829 times.
✗ Branch 208 not taken.
✓ Branch 209 taken 178 times.
✓ Branch 210 taken 236 times.
✓ Branch 211 taken 140 times.
✓ Branch 212 taken 3783 times.
✗ Branch 213 not taken.
✗ Branch 214 not taken.
✗ Branch 215 not taken.
✗ Branch 216 not taken.
✓ Branch 217 taken 1117 times.
✗ Branch 218 not taken.
✓ Branch 219 taken 2768 times.
✓ Branch 220 taken 1452537 times.
✗ Branch 221 not taken.
✗ Branch 222 not taken.
✓ Branch 223 taken 585769 times.
✗ Branch 224 not taken.
✗ Branch 225 not taken.
✗ Branch 226 not taken.
✓ Branch 227 taken 6365 times.
✗ Branch 228 not taken.
✓ Branch 229 taken 432438 times.
✗ Branch 230 not taken.
✓ Branch 231 taken 3209685 times.
✗ Branch 232 not taken.
✗ Branch 233 not taken.
✓ Branch 234 taken 177544 times.
✗ Branch 235 not taken.
✓ Branch 236 taken 16 times.
✗ Branch 237 not taken.
✓ Branch 238 taken 8 times.
✗ Branch 239 not taken.
✗ Branch 240 not taken.
✓ Branch 241 taken 223 times.
✓ Branch 242 taken 11 times.
✗ Branch 243 not taken.
✗ Branch 244 not taken.
✓ Branch 245 taken 11 times.
✗ Branch 246 not taken.
✗ Branch 247 not taken.
✓ Branch 248 taken 24 times.
✓ Branch 249 taken 87 times.
✓ Branch 250 taken 92 times.
✗ Branch 251 not taken.
✗ Branch 252 not taken.
✓ Branch 253 taken 370 times.
✗ Branch 254 not taken.
✓ Branch 255 taken 31 times.
✗ Branch 256 not taken.
✓ Branch 257 taken 1064 times.
✓ Branch 258 taken 130 times.
✗ Branch 259 not taken.
✗ Branch 260 not taken.
✗ Branch 261 not taken.
✗ Branch 262 not taken.
✗ Branch 263 not taken.
✓ Branch 264 taken 450 times.
✓ Branch 265 taken 4781 times.
✗ Branch 266 not taken.
✓ Branch 267 taken 112 times.
✓ Branch 268 taken 234 times.
✗ Branch 269 not taken.
✓ Branch 270 taken 628 times.
✓ Branch 271 taken 53 times.
✗ Branch 272 not taken.
✗ Branch 273 not taken.
✗ Branch 274 not taken.
✗ Branch 275 not taken.
✗ Branch 276 not taken.
✗ Branch 277 not taken.
✗ Branch 278 not taken.
✗ Branch 279 not taken.
✗ Branch 280 not taken.
✗ Branch 281 not taken.
✗ Branch 282 not taken.
✗ Branch 283 not taken.
✗ Branch 284 not taken.
✗ Branch 285 not taken.
✗ Branch 286 not taken.
✗ Branch 287 not taken.
✓ Branch 288 taken 24 times.
✗ Branch 289 not taken.
✓ Branch 290 taken 24 times.
✗ Branch 291 not taken.
✗ Branch 292 not taken.
✗ Branch 293 not taken.
✗ Branch 294 not taken.
✓ Branch 295 taken 12 times.
✓ Branch 296 taken 598 times.
✗ Branch 297 not taken.
✓ Branch 298 taken 27870027 times.
✓ Branch 299 taken 87667 times.
✗ Branch 300 not taken.
✓ Branch 301 taken 209493 times.
✗ Branch 302 not taken.
✓ Branch 303 taken 3530 times.
✓ Branch 304 taken 573 times.
✓ Branch 305 taken 31487 times.
✓ Branch 306 taken 5 times.
✓ Branch 307 taken 11754119 times.
✓ Branch 308 taken 160009 times.
✗ Branch 309 not taken.
✗ Branch 310 not taken.
✗ Branch 311 not taken.
✓ Branch 312 taken 19653 times.
✗ Branch 313 not taken.
✗ Branch 314 not taken.
✓ Branch 315 taken 21032557 times.
✗ Branch 316 not taken.
✗ Branch 317 not taken.
✓ Branch 318 taken 257 times.
✓ Branch 319 taken 354947 times.
✓ Branch 320 taken 3 times.
✗ Branch 321 not taken.
✓ Branch 322 taken 354994 times.
✓ Branch 323 taken 50 times.
✓ Branch 324 taken 3 times.
✓ Branch 325 taken 13670631 times.
✓ Branch 326 taken 18282859 times.
✓ Branch 327 taken 357 times.
✗ Branch 328 not taken.
✗ Branch 329 not taken.
✓ Branch 330 taken 3062 times.
✓ Branch 331 taken 3512 times.
✗ Branch 332 not taken.
✗ Branch 333 not taken.
✗ Branch 334 not taken.
✗ Branch 335 not taken.
✓ Branch 336 taken 49233778 times.
✗ Branch 337 not taken.
✗ Branch 338 not taken.
✗ Branch 339 not taken.
✗ Branch 340 not taken.
✗ Branch 341 not taken.
✓ Branch 342 taken 10 times.
✗ Branch 343 not taken.
✗ Branch 344 not taken.
✗ Branch 345 not taken.
✓ Branch 346 taken 57032 times.
✗ Branch 347 not taken.
✗ Branch 348 not taken.
✗ Branch 349 not taken.
✗ Branch 350 not taken.
✗ Branch 351 not taken.
✗ Branch 352 not taken.
✗ Branch 353 not taken.
✗ Branch 354 not taken.
✗ Branch 355 not taken.
✗ Branch 356 not taken.
✓ Branch 357 taken 7069332 times.
✓ Branch 358 taken 28 times.
✗ Branch 359 not taken.
✗ Branch 360 not taken.
✗ Branch 361 not taken.
✗ Branch 362 not taken.
✗ Branch 363 not taken.
✗ Branch 364 not taken.
✗ Branch 365 not taken.
✗ Branch 366 not taken.
✗ Branch 367 not taken.
✗ Branch 368 not taken.
✗ Branch 369 not taken.
✗ Branch 370 not taken.
✗ Branch 371 not taken.
✗ Branch 372 not taken.
✗ Branch 373 not taken.
✗ Branch 374 not taken.
✗ Branch 375 not taken.
✗ Branch 376 not taken.
✓ Branch 377 taken 3596 times.
✗ Branch 378 not taken.
✗ Branch 379 not taken.
✓ Branch 380 taken 440764 times.
✗ Branch 381 not taken.
✗ Branch 382 not taken.
✗ Branch 383 not taken.
✗ Branch 384 not taken.
✗ Branch 385 not taken.
✗ Branch 386 not taken.
✗ Branch 387 not taken.
✗ Branch 388 not taken.
✗ Branch 389 not taken.
✗ Branch 390 not taken.
✗ Branch 391 not taken.
✗ Branch 392 not taken.
✗ Branch 393 not taken.
✗ Branch 394 not taken.
✗ Branch 395 not taken.
✗ Branch 396 not taken.
✗ Branch 397 not taken.
✗ Branch 398 not taken.
✗ Branch 399 not taken.
✗ Branch 400 not taken.
✗ Branch 401 not taken.
✗ Branch 402 not taken.
✗ Branch 403 not taken.
✗ Branch 404 not taken.
✗ Branch 405 not taken.
✗ Branch 406 not taken.
✗ Branch 407 not taken.
✗ Branch 408 not taken.
✗ Branch 409 not taken.
✗ Branch 410 not taken.
✗ Branch 411 not taken.
✗ Branch 412 not taken.
✗ Branch 413 not taken.
✗ Branch 414 not taken.
✗ Branch 415 not taken.
✗ Branch 416 not taken.
✗ Branch 417 not taken.
✗ Branch 418 not taken.
✗ Branch 419 not taken.
✗ Branch 420 not taken.
✗ Branch 421 not taken.
✗ Branch 422 not taken.
✗ Branch 423 not taken.
✗ Branch 424 not taken.
✗ Branch 425 not taken.
✗ Branch 426 not taken.
✗ Branch 427 not taken.
✗ Branch 428 not taken.
✗ Branch 429 not taken.
✗ Branch 430 not taken.
✗ Branch 431 not taken.
✗ Branch 432 not taken.
✗ Branch 433 not taken.
✗ Branch 434 not taken.
✗ Branch 435 not taken.
✗ Branch 436 not taken.
✗ Branch 437 not taken.
✗ Branch 438 not taken.
✗ Branch 439 not taken.
✗ Branch 440 not taken.
✗ Branch 441 not taken.
✗ Branch 442 not taken.
✗ Branch 443 not taken.
✗ Branch 444 not taken.
✗ Branch 445 not taken.
✗ Branch 446 not taken.
✗ Branch 447 not taken.
✗ Branch 448 not taken.
✗ Branch 449 not taken.
✗ Branch 450 not taken.
✗ Branch 451 not taken.
✗ Branch 452 not taken.
✗ Branch 453 not taken.
✗ Branch 454 not taken.
✗ Branch 455 not taken.
✗ Branch 456 not taken.
✗ Branch 457 not taken.
✗ Branch 458 not taken.
✗ Branch 459 not taken.
✗ Branch 460 not taken.
✗ Branch 461 not taken.
✗ Branch 462 not taken.
✗ Branch 463 not taken.
✗ Branch 464 not taken.
✗ Branch 465 not taken.
✗ Branch 466 not taken.
✗ Branch 467 not taken.
✗ Branch 468 not taken.
✗ Branch 469 not taken.
✗ Branch 470 not taken.
✗ Branch 471 not taken.
✗ Branch 472 not taken.
✗ Branch 473 not taken.
✗ Branch 474 not taken.
✗ Branch 475 not taken.
✗ Branch 476 not taken.
✗ Branch 477 not taken.
✗ Branch 478 not taken.
✗ Branch 479 not taken.
✗ Branch 480 not taken.
✗ Branch 481 not taken.
✗ Branch 482 not taken.
✗ Branch 483 not taken.
✗ Branch 484 not taken.
✗ Branch 485 not taken.
✗ Branch 486 not taken.
✗ Branch 487 not taken.
✗ Branch 488 not taken.
✗ Branch 489 not taken.
✗ Branch 490 not taken.
✗ Branch 491 not taken.
✗ Branch 492 not taken.
✗ Branch 493 not taken.
✗ Branch 494 not taken.
✗ Branch 495 not taken.
✗ Branch 496 not taken.
✗ Branch 497 not taken.
✗ Branch 498 not taken.
✗ Branch 499 not taken.
✗ Branch 500 not taken.
✗ Branch 501 not taken.
✗ Branch 502 not taken.
✗ Branch 503 not taken.
✗ Branch 504 not taken.
✗ Branch 505 not taken.
✗ Branch 506 not taken.
✗ Branch 507 not taken.
✗ Branch 508 not taken.
✗ Branch 509 not taken.
✗ Branch 510 not taken.
✗ Branch 511 not taken.
✗ Branch 512 not taken.
✗ Branch 513 not taken.
✗ Branch 514 not taken.
✗ Branch 515 not taken.
✗ Branch 516 not taken.
✗ Branch 517 not taken.
✗ Branch 518 not taken.
✗ Branch 519 not taken.
✗ Branch 520 not taken.
✗ Branch 521 not taken.
✗ Branch 522 not taken.
✗ Branch 523 not taken.
✗ Branch 524 not taken.
✗ Branch 525 not taken.
✗ Branch 526 not taken.
✗ Branch 527 not taken.
✗ Branch 528 not taken.
✗ Branch 529 not taken.
✗ Branch 530 not taken.
✗ Branch 531 not taken.
✗ Branch 532 not taken.
✗ Branch 533 not taken.
✗ Branch 534 not taken.
✗ Branch 535 not taken.
✗ Branch 536 not taken.
✗ Branch 537 not taken.
✗ Branch 538 not taken.
✗ Branch 539 not taken.
✗ Branch 540 not taken.
✗ Branch 541 not taken.
✗ Branch 542 not taken.
✗ Branch 543 not taken.
✗ Branch 544 not taken.
✗ Branch 545 not taken.
✗ Branch 546 not taken.
✗ Branch 547 not taken.
✗ Branch 548 not taken.
✗ Branch 549 not taken.
✗ Branch 550 not taken.
✗ Branch 551 not taken.
✗ Branch 552 not taken.
✗ Branch 553 not taken.
✗ Branch 554 not taken.
✗ Branch 555 not taken.
✗ Branch 556 not taken.
✗ Branch 557 not taken.
✗ Branch 558 not taken.
✗ Branch 559 not taken.
✗ Branch 560 not taken.
✗ Branch 561 not taken.
✗ Branch 562 not taken.
✗ Branch 563 not taken.
✗ Branch 564 not taken.
✗ Branch 565 not taken.
✗ Branch 566 not taken.
✗ Branch 567 not taken.
✗ Branch 568 not taken.
✗ Branch 569 not taken.
✗ Branch 570 not taken.
✗ Branch 571 not taken.
✗ Branch 572 not taken.
✗ Branch 573 not taken.
✗ Branch 574 not taken.
✗ Branch 575 not taken.
✗ Branch 576 not taken.
✗ Branch 577 not taken.
✗ Branch 578 not taken.
✗ Branch 579 not taken.
✗ Branch 580 not taken.
✗ Branch 581 not taken.
✗ Branch 582 not taken.
✗ Branch 583 not taken.
✗ Branch 584 not taken.
✗ Branch 585 not taken.
✗ Branch 586 not taken.
✗ Branch 587 not taken.
✗ Branch 588 not taken.
✗ Branch 589 not taken.
✗ Branch 590 not taken.
✗ Branch 591 not taken.
✗ Branch 592 not taken.
✗ Branch 593 not taken.
✗ Branch 594 not taken.
✗ Branch 595 not taken.
✗ Branch 596 not taken.
✗ Branch 597 not taken.
✗ Branch 598 not taken.
✗ Branch 599 not taken.
✗ Branch 600 not taken.
✗ Branch 601 not taken.
✗ Branch 602 not taken.
✗ Branch 603 not taken.
✗ Branch 604 not taken.
✗ Branch 605 not taken.
✗ Branch 606 not taken.
✗ Branch 607 not taken.
✗ Branch 608 not taken.
✗ Branch 609 not taken.
✗ Branch 610 not taken.
✗ Branch 611 not taken.
✓ Branch 612 taken 3 times.
✓ Branch 613 taken 5 times.
✗ Branch 614 not taken.
✗ Branch 615 not taken.
✗ Branch 616 not taken.
✗ Branch 617 not taken.
✗ Branch 618 not taken.
✗ Branch 619 not taken.
✗ Branch 620 not taken.
✗ Branch 621 not taken.
✓ Branch 622 taken 7 times.
✗ Branch 623 not taken.
✓ Branch 624 taken 1 times.
✗ Branch 625 not taken.
✗ Branch 626 not taken.
✓ Branch 627 taken 1 times.
✗ Branch 628 not taken.
✗ Branch 629 not taken.
✗ Branch 630 not taken.
✗ Branch 631 not taken.
✓ Branch 632 taken 1 times.
✗ Branch 633 not taken.
✓ Branch 634 taken 279 times.
✗ Branch 635 not taken.
✗ Branch 636 not taken.
✗ Branch 637 not taken.
✗ Branch 638 not taken.
✗ Branch 639 not taken.
✗ Branch 640 not taken.
✗ Branch 641 not taken.
✗ Branch 642 not taken.
✗ Branch 643 not taken.
✗ Branch 644 not taken.
✗ Branch 645 not taken.
✗ Branch 646 not taken.
✗ Branch 647 not taken.
✗ Branch 648 not taken.
✗ Branch 649 not taken.
✗ Branch 650 not taken.
✗ Branch 651 not taken.
✗ Branch 652 not taken.
✗ Branch 653 not taken.
✗ Branch 654 not taken.
✓ Branch 655 taken 8 times.
✓ Branch 656 taken 10 times.
✗ Branch 657 not taken.
✗ Branch 658 not taken.
✗ Branch 659 not taken.
✗ Branch 660 not taken.
✓ Branch 661 taken 14870 times.
✗ Branch 662 not taken.
✗ Branch 663 not taken.
✗ Branch 664 not taken.
✗ Branch 665 not taken.
✓ Branch 666 taken 828 times.
✗ Branch 667 not taken.
✗ Branch 668 not taken.
✗ Branch 669 not taken.
✓ Branch 670 taken 76234 times.
✓ Branch 671 taken 10 times.
✗ Branch 672 not taken.
✓ Branch 673 taken 53638474 times.
✓ Branch 674 taken 45321202 times.
✗ Branch 675 not taken.
✗ Branch 676 not taken.
✓ Branch 677 taken 1180630 times.
✗ Branch 678 not taken.
✓ Branch 679 taken 82663 times.
✓ Branch 680 taken 12134 times.
✓ Branch 681 taken 958 times.
✓ Branch 682 taken 8 times.
✓ Branch 683 taken 11 times.
✗ Branch 684 not taken.
✓ Branch 685 taken 3 times.
✗ Branch 686 not taken.
✓ Branch 687 taken 1974 times.
✓ Branch 688 taken 932 times.
✓ Branch 689 taken 65 times.
✓ Branch 690 taken 185 times.
✗ Branch 691 not taken.
✗ Branch 692 not taken.
✓ Branch 693 taken 1470 times.
✗ Branch 694 not taken.
✗ Branch 695 not taken.
✓ Branch 696 taken 61 times.
✗ Branch 697 not taken.
✓ Branch 698 taken 8 times.
✗ Branch 699 not taken.
✓ Branch 700 taken 2162 times.
✗ Branch 701 not taken.
✓ Branch 702 taken 13775417 times.
✓ Branch 703 taken 2 times.
✓ Branch 704 taken 303067642 times.
✓ Branch 705 taken 3358320 times.
✗ Branch 706 not taken.
✓ Branch 707 taken 13 times.
✓ Branch 708 taken 16 times.
✗ Branch 709 not taken.
✗ Branch 710 not taken.
✗ Branch 711 not taken.
✓ Branch 712 taken 105 times.
✗ Branch 713 not taken.
✗ Branch 714 not taken.
✓ Branch 715 taken 2397 times.
✓ Branch 716 taken 140579 times.
✓ Branch 717 taken 28 times.
✓ Branch 718 taken 2674 times.
✗ Branch 719 not taken.
✓ Branch 720 taken 2912197 times.
✗ Branch 721 not taken.
✓ Branch 722 taken 6556 times.
✗ Branch 723 not taken.
✓ Branch 724 taken 3 times.
✗ Branch 725 not taken.
✓ Branch 726 taken 107 times.
✓ Branch 727 taken 127 times.
✓ Branch 728 taken 2004 times.
✗ Branch 729 not taken.
✓ Branch 730 taken 1 times.
✗ Branch 731 not taken.
✗ Branch 732 not taken.
✗ Branch 733 not taken.
✗ Branch 734 not taken.
✓ Branch 735 taken 14 times.
✗ Branch 736 not taken.
✗ Branch 737 not taken.
✗ Branch 738 not taken.
✗ Branch 739 not taken.
✓ Branch 740 taken 4712414 times.
✓ Branch 741 taken 5620654 times.
✗ Branch 742 not taken.
✗ Branch 743 not taken.
✗ Branch 744 not taken.
✗ Branch 745 not taken.
✗ Branch 746 not taken.
✗ Branch 747 not taken.
✓ Branch 748 taken 22443 times.
✗ Branch 749 not taken.
✓ Branch 750 taken 43 times.
✓ Branch 751 taken 1205956 times.
✗ Branch 752 not taken.
✓ Branch 753 taken 208946 times.
✗ Branch 754 not taken.
✗ Branch 755 not taken.
✗ Branch 756 not taken.
✓ Branch 757 taken 5 times.
✓ Branch 758 taken 118 times.
✗ Branch 759 not taken.
✗ Branch 760 not taken.
✗ Branch 761 not taken.
✗ Branch 762 not taken.
✓ Branch 763 taken 26528 times.
✓ Branch 764 taken 146 times.
✗ Branch 765 not taken.
✗ Branch 766 not taken.
✗ Branch 767 not taken.
✗ Branch 768 not taken.
✗ Branch 769 not taken.
✗ Branch 770 not taken.
✓ Branch 771 taken 4 times.
✓ Branch 772 taken 6 times.
✓ Branch 773 taken 2 times.
✗ Branch 774 not taken.
✓ Branch 775 taken 27 times.
✗ Branch 776 not taken.
✗ Branch 777 not taken.
✓ Branch 778 taken 3560 times.
✓ Branch 779 taken 66 times.
✗ Branch 780 not taken.
✗ Branch 781 not taken.
✗ Branch 782 not taken.
✗ Branch 783 not taken.
✗ Branch 784 not taken.
✗ Branch 785 not taken.
✓ Branch 786 taken 92 times.
✓ Branch 787 taken 1798 times.
✗ Branch 788 not taken.
✗ Branch 789 not taken.
✗ Branch 790 not taken.
✗ Branch 791 not taken.
✗ Branch 792 not taken.
✗ Branch 793 not taken.
✗ Branch 794 not taken.
✗ Branch 795 not taken.
✗ Branch 796 not taken.
✗ Branch 797 not taken.
✗ Branch 798 not taken.
✗ Branch 799 not taken.
✗ Branch 800 not taken.
✗ Branch 801 not taken.
✗ Branch 802 not taken.
✓ Branch 803 taken 15 times.
✗ Branch 804 not taken.
✗ Branch 805 not taken.
✗ Branch 806 not taken.
✗ Branch 807 not taken.
✗ Branch 808 not taken.
✗ Branch 809 not taken.
✗ Branch 810 not taken.
✗ Branch 811 not taken.
✗ Branch 812 not taken.
✗ Branch 813 not taken.
✗ Branch 814 not taken.
✗ Branch 815 not taken.
✗ Branch 816 not taken.
✗ Branch 817 not taken.
✗ Branch 818 not taken.
✗ Branch 819 not taken.
✗ Branch 820 not taken.
✗ Branch 821 not taken.
✗ Branch 822 not taken.
✗ Branch 823 not taken.
✗ Branch 824 not taken.
✗ Branch 825 not taken.
✗ Branch 826 not taken.
✗ Branch 827 not taken.
✗ Branch 828 not taken.
✗ Branch 829 not taken.
✗ Branch 830 not taken.
✗ Branch 831 not taken.
✗ Branch 832 not taken.
✗ Branch 833 not taken.
✗ Branch 834 not taken.
✗ Branch 835 not taken.
✗ Branch 836 not taken.
✗ Branch 837 not taken.
✗ Branch 838 not taken.
✗ Branch 839 not taken.
✗ Branch 840 not taken.
✓ Branch 841 taken 8 times.
✓ Branch 842 taken 46 times.
✗ Branch 843 not taken.
✗ Branch 844 not taken.
✗ Branch 845 not taken.
✗ Branch 846 not taken.
✗ Branch 847 not taken.
✓ Branch 848 taken 1 times.
✗ Branch 849 not taken.
✓ Branch 850 taken 1 times.
✗ Branch 851 not taken.
✗ Branch 852 not taken.
✗ Branch 853 not taken.
✗ Branch 854 not taken.
✗ Branch 855 not taken.
✗ Branch 856 not taken.
✗ Branch 857 not taken.
✗ Branch 858 not taken.
✓ Branch 859 taken 1338 times.
✓ Branch 860 taken 448056 times.
✗ Branch 861 not taken.
✗ Branch 862 not taken.
✗ Branch 863 not taken.
✓ Branch 864 taken 73 times.
✗ Branch 865 not taken.
✓ Branch 866 taken 6 times.
✓ Branch 867 taken 137106 times.
✓ Branch 868 taken 17877 times.
✗ Branch 869 not taken.
✗ Branch 870 not taken.
✓ Branch 871 taken 1120 times.
✗ Branch 872 not taken.
✓ Branch 873 taken 150 times.
✓ Branch 874 taken 1120 times.
✓ Branch 875 taken 348 times.
✓ Branch 876 taken 140 times.
✓ Branch 877 taken 8 times.
1147784569 switch(scommand)
30628 {
30629 //always first
30630 case 0xFFFF: //invalid command
30631 {
30632 const char* type_str = ScriptTypeToString(type);
30633 switch(type)
30634 {
30635 case ScriptType::FFC:
30636 zprint("%s Script %s has exited.\n", type_str, ffcmap[i].scriptname.c_str()); break;
30637 case ScriptType::NPC:
30638 zprint("%s Script %s has exited.\n", type_str, npcmap[i].scriptname.c_str()); break;
30639 case ScriptType::Lwpn:
30640 zprint("%s Script %s has exited.\n", type_str, lwpnmap[i].scriptname.c_str()); break;
30641 case ScriptType::Ewpn:
30642 zprint("%s Script %s has exited.\n", type_str, ewpnmap[i].scriptname.c_str()); break;
30643 case ScriptType::ItemSprite:
30644 zprint("%s Script %s has exited.\n", type_str, itemspritemap[i].scriptname.c_str()); break;
30645 case ScriptType::Item:
30646 zprint("%s Script %s has exited.\n", type_str, itemmap[i].scriptname.c_str()); break;
30647 case ScriptType::Global:
30648 zprint("%s Script %s has exited.\n", type_str, globalmap[i].scriptname.c_str()); break;
30649 case ScriptType::Hero:
30650 zprint("%s Script %s has exited.\n", type_str, playermap[i].scriptname.c_str()); break;
30651 case ScriptType::Screen:
30652 zprint("%s Script %s has exited.\n", type_str, screenmap[i].scriptname.c_str()); break;
30653 case ScriptType::OnMap:
30654 case ScriptType::DMap:
30655 case ScriptType::ScriptedActiveSubscreen:
30656 case ScriptType::ScriptedPassiveSubscreen:
30657 zprint("%s Script %s has exited.\n", type_str, dmapmap[i].scriptname.c_str()); break;
30658 case ScriptType::Combo: zprint("%s Script %s has exited.\n", type_str, comboscriptmap[i].scriptname.c_str()); break;
30659
30660 default: break;
30661 }
30662 break;
30663 }
30664 case QUIT:
30665 82663 scommand = 0xFFFF;
30666 82663 break;
30667 case QUIT_NO_DEALLOC:
30668 scommand = 0xFFFF;
30669 no_dealloc = true;
30670 break;
30671
30672 case NOP: //No Operation. Do nothing. -Em
30673 {
30674 // While we are here, skip many NOPs in a row to avoid the overhead
30675 // of the interpreter loop. This is especially good for how `zasm_optimize`
30676 // works, since it replaces many commands with a sequence of NOPs.
30677 // No need to do a bounds check - the last command should always be 0xFFFF.
30678
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12134 times.
12134 if (is_debugging)
30679 break;
30680
2/2
✓ Branch 0 taken 15139 times.
✓ Branch 1 taken 12134 times.
27273 while (zasm[ri->pc + 1].command == NOP)
30681 15139 ri->pc++;
30682 12134 break;
30683 }
30684 case GOTO:
30685 {
30686
1/2
✓ Branch 0 taken 958 times.
✗ Branch 1 not taken.
958 if(sarg1 < 0 )
30687 {
30688 goto_err("GOTO");
30689 scommand = 0xFFFF;
30690 break;
30691 }
30692 958 ri->pc = sarg1;
30693 958 increment = false;
30694 958 break;
30695 }
30696 case GOTOR:
30697 {
30698
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(sarg1 < 0 )
30699 {
30700 goto_err("GOTOR");
30701 scommand = 0xFFFF;
30702 break;
30703 }
30704 8 ri->pc = (get_register(sarg1) / 10000) - 1;
30705 8 increment = false;
30706 }
30707 8 break;
30708
30709 case GOTOTRUE:
30710
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 7 times.
11 if(check_cmp(CMP_EQ))
30711 {
30712
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(sarg1 < 0 )
30713 {
30714 goto_err("GOTOTRUE");
30715 scommand = 0xFFFF;
30716 break;
30717 }
30718 7 ri->pc = sarg1;
30719 7 increment = false;
30720 7 }
30721 11 break;
30722
30723 case GOTOFALSE:
30724 if(check_cmp(CMP_NE))
30725 {
30726 if(sarg1 < 0 )
30727 {
30728 goto_err("GOTOFALSE");
30729 scommand = 0xFFFF;
30730 break;
30731 }
30732 ri->pc = sarg1;
30733 increment = false;
30734 }
30735 break;
30736
30737 case GOTOMORE:
30738
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if(check_cmp(CMP_GE))
30739 {
30740
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(sarg1 < 0 )
30741 {
30742 goto_err("GOTOMORE");
30743 scommand = 0xFFFF;
30744 break;
30745 }
30746 2 ri->pc = sarg1;
30747 2 increment = false;
30748 2 }
30749 3 break;
30750
30751 case GOTOLESS:
30752 if(check_cmp(get_qr(qr_GOTOLESSNOTEQUAL) ? CMP_LT : CMP_LE))
30753 {
30754 if(sarg1 < 0 )
30755 {
30756 goto_err("GOTOLESS");
30757 scommand = 0xFFFF;
30758 break;
30759 }
30760 ri->pc = sarg1;
30761 increment = false;
30762 }
30763 break;
30764
30765 case GOTOCMP:
30766 {
30767 1974 bool run = check_cmp(sarg2);
30768
2/2
✓ Branch 0 taken 1177 times.
✓ Branch 1 taken 797 times.
1974 if(run)
30769 {
30770
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 797 times.
797 if(sarg1 < 0 )
30771 {
30772 goto_err("GOTOCMP");
30773 scommand = 0xFFFF;
30774 break;
30775 }
30776 797 ri->pc = sarg1;
30777 797 increment = false;
30778 797 }
30779 1974 break;
30780 }
30781
30782 case SETCMP:
30783 {
30784 932 bool run = check_cmp(sarg2);
30785
2/2
✓ Branch 0 taken 910 times.
✓ Branch 1 taken 22 times.
932 set_register(sarg1, run ? ((sarg2 & CMP_SETI) ? 10000 : 1) : 0);
30786 932 break;
30787 }
30788
30789 case CALLFUNC:
30790 {
30791 65 retstack_push(ri->pc+1);
30792
1/2
✓ Branch 0 taken 65 times.
✗ Branch 1 not taken.
65 if(sarg1 < 0 )
30793 {
30794 goto_err("CALLFUNC");
30795 scommand = 0xFFFF;
30796 break;
30797 }
30798 65 ri->pc = sarg1;
30799 65 increment = false;
30800 65 break;
30801 }
30802 case RETURNFUNC:
30803 {
30804
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 120 times.
185 if(auto retpc = retstack_pop())
30805 {
30806
1/2
✓ Branch 0 taken 65 times.
✗ Branch 1 not taken.
65 if(*retpc < 0)
30807 {
30808 goto_err("RETURNFUNC");
30809 scommand = 0xFFFF;
30810 break;
30811 }
30812 65 ri->pc = *retpc;
30813 65 increment = false;
30814 65 }
30815 else //Returned from 'void run()', QUIT
30816 {
30817 120 scommand = 0xFFFF;
30818 }
30819 185 break;
30820 }
30821
30822 case LOOP:
30823 {
30824 if(get_register(sarg2) > 0)
30825 {
30826 ri->pc = sarg1;
30827 increment = false;
30828 }
30829 else
30830 {
30831 set_register(sarg1, sarg1 - 1);
30832 }
30833 }
30834 break;
30835
30836 case RETURN:
30837 {
30838 if (script_funcrun)
30839 break; //handled below, poorly. 'RETURNFUNC' does this better now.
30840 ri->pc = SH::read_stack(ri->sp) - 1;
30841 ++ri->sp;
30842 ri->sp &= MASK_SP;
30843 increment = false;
30844 break;
30845 }
30846
30847 case SETTRUE:
30848 4 set_register(sarg1, check_cmp(CMP_EQ) ? 1 : 0);
30849 4 break;
30850
30851 case SETFALSE:
30852 12 set_register(sarg1, check_cmp(CMP_NE) ? 1 : 0);
30853 12 break;
30854
30855 case SETMORE:
30856 4 set_register(sarg1, check_cmp(CMP_GE) ? 1 : 0);
30857 4 break;
30858
30859 case SETLESS:
30860 set_register(sarg1, check_cmp(CMP_LE) ? 1 : 0);
30861 break;
30862
30863 case SETTRUEI:
30864 2 set_register(sarg1, check_cmp(CMP_EQ) ? 10000 : 0);
30865 2 break;
30866
30867 case SETFALSEI:
30868 set_register(sarg1, check_cmp(CMP_NE) ? 10000 : 0);
30869 break;
30870
30871 case SETMOREI:
30872 5 set_register(sarg1, check_cmp(CMP_GE) ? 10000 : 0);
30873 5 break;
30874
30875 case SETLESSI:
30876 set_register(sarg1, check_cmp(CMP_LE) ? 10000 : 0);
30877 break;
30878
30879 case READPODARRAYR:
30880 {
30881 151434482 do_readpod(false);
30882 151434482 break;
30883 }
30884 case READPODARRAYV:
30885 {
30886 81459140 do_readpod(true);
30887 81459140 break;
30888 }
30889 case WRITEPODARRAYRR:
30890 {
30891 50481826 do_writepod(false,false);
30892 50481826 break;
30893 }
30894 case WRITEPODARRAYRV:
30895 {
30896 do_writepod(false,true);
30897 break;
30898 }
30899 case WRITEPODARRAYVR:
30900 {
30901 80754051 do_writepod(true,false);
30902 80754051 break;
30903 }
30904 case WRITEPODARRAYVV:
30905 {
30906 2929235 do_writepod(true,true);
30907 2929235 break;
30908 }
30909 case WRITEPODSTRING:
30910 {
30911 3239555 do_writepodstr();
30912 3239555 break;
30913 }
30914 case WRITEPODARRAY:
30915 {
30916 560107 do_writepodarr();
30917 560107 break;
30918 }
30919
30920 case NOT:
30921 do_not(false);
30922 break;
30923
30924 case COMPAREV:
30925 603 do_comp(true);
30926 603 break;
30927 case COMPAREV2:
30928 do_comp(true,true);
30929 break;
30930
30931 case COMPARER:
30932 1410 do_comp(false);
30933 1410 break;
30934
30935 case STRCMPR:
30936 do_internal_strcmp();
30937 break;
30938
30939 case STRICMPR:
30940 do_internal_stricmp();
30941 break;
30942
30943 case SETV:
30944 2448 do_set(true, type, i);
30945 2448 break;
30946
30947 case SETR:
30948 1470 do_set(false, type, i);
30949 1470 break;
30950
30951 case PUSHR:
30952 4382 do_push(false);
30953 4382 break;
30954
30955 case PUSHV:
30956 1454 do_push(true);
30957 1454 break;
30958
30959 case PEEK:
30960 do_peek();
30961 break;
30962 case PEEKATV:
30963 28 do_peekat(true);
30964 28 break;
30965 case STACKWRITEATRV:
30966 do_writeat(false, true);
30967 break;
30968 case STACKWRITEATVV_IF:
30969 if(!check_cmp(sarg3))
30970 break;
30971 [[fallthrough]];
30972 case STACKWRITEATVV:
30973 do_writeat(true, true);
30974 break;
30975 case POP:
30976 5548 do_pop();
30977 5548 break;
30978
30979 case POPARGS:
30980 61 do_pops();
30981 61 break;
30982
30983 case PUSHARGSR:
30984 25 do_pushs(false);
30985 25 break;
30986
30987 case PUSHARGSV:
30988 do_pushs(true);
30989 break;
30990
30991 case LOADI:
30992 50 do_loadi();
30993 50 break;
30994
30995 case STOREI:
30996 8 do_storei();
30997 8 break;
30998
30999 case LOADD:
31000 do_loadd();
31001 break;
31002
31003 case LOAD:
31004 6044 do_load();
31005 6044 break;
31006
31007 case STORED:
31008 do_stored(false);
31009 break;
31010 case STOREDV:
31011 do_stored(true);
31012 break;
31013 case STORE:
31014 2162 do_store(false);
31015 2162 break;
31016 case STOREV:
31017 do_store(true);
31018 break;
31019 case STORE_OBJECT:
31020 do_store_object(false);
31021 break;
31022
31023 case ALLOCATEGMEMR:
31024 if(type == ScriptType::Global) do_allocatemem(false, false, type, i);
31025
31026 break;
31027
31028 case ALLOCATEGMEMV:
31029
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2959 times.
2959 if(type == ScriptType::Global) do_allocatemem(true, false, type, i);
31030
31031 2959 break;
31032
31033 case ALLOCATEMEMR:
31034 do_allocatemem(false, true, type, i);
31035 break;
31036
31037 case ALLOCATEMEMV:
31038 13775417 do_allocatemem(true, true, type, i);
31039 13775417 break;
31040
31041 case RESIZEARRAYR:
31042 2 do_resize_array();
31043 2 break;
31044 case OWNARRAYR:
31045 do_own_array(get_register(sarg1)/10000, type, i);
31046 break;
31047 case DESTROYARRAYR:
31048 do_destroy_array();
31049 break;
31050
31051 case DEALLOCATEMEMR:
31052 13741280 do_deallocatemem();
31053 13741280 break;
31054
31055 case SAVEGAMESTRUCTS:
31056 10 using_SRAM = 1;
31057 10 FFCore.do_savegamestructs(false,false);
31058 10 using_SRAM = 0;
31059 10 break;
31060 case READGAMESTRUCTS:
31061 using_SRAM = 1;
31062 FFCore.do_loadgamestructs(false,false);
31063 using_SRAM = 0;
31064 break;
31065 case ARRAYSIZE:
31066 303067642 do_arraysize();
31067 303067642 break;
31068
31069 case GETFFCSCRIPT:
31070 10105619 do_getffcscript();
31071 10105619 break;
31072 case GETITEMSCRIPT:
31073 80 do_getitemscript();
31074 80 break;
31075
31076 case LOAD_FFC:
31077 {
31078
1/2
✓ Branch 0 taken 3358320 times.
✗ Branch 1 not taken.
3358320 if (!ZScriptVersion::ffcRefIsSpriteId())
31079 {
31080 set_register(sarg1, get_register(sarg1) - 10000);
31081 break;
31082 }
31083
31084 3358320 int ffc_id = get_register(sarg1) / 10000 - 1;
31085
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3358320 times.
3358320 if (auto ffc = ResolveFFCWithID(ffc_id))
31086 3358320 set_register(sarg1, ffc->getUID());
31087 else
31088 set_register(sarg1, 0);
31089 3358320 break;
31090 }
31091
31092 case LOAD_FFC_2:
31093 {
31094 if (!ZScriptVersion::ffcRefIsSpriteId())
31095 {
31096 set_register(sarg1, get_register(sarg2) - 10000);
31097 break;
31098 }
31099
31100 int screen = get_register(sarg1) / 10000;
31101 int index = get_register(sarg2) / 10000;
31102
31103 if (!is_in_current_region(screen))
31104 {
31105 scripting_log_error_with_context("Must use a screen in the current region. got: {}", screen);
31106 break;
31107 }
31108 if (BC::checkMapdataFFC(index) != SH::_NoError)
31109 break;
31110
31111 ffc_id_t ffc_id = get_region_screen_offset(screen)*MAXFFCS + index;
31112 if (auto ffc = ResolveFFCWithID(ffc_id))
31113 set_register(sarg1, ffc->getUID());
31114 else
31115 set_register(sarg1, 0);
31116
31117 break;
31118 }
31119
31120 case CASTBOOLI:
31121 13 do_boolcast(false);
31122 13 break;
31123
31124 case CASTBOOLF:
31125 4 do_boolcast(true);
31126 4 break;
31127
31128 case ADDV:
31129 987 do_add(true);
31130 987 break;
31131
31132 case ADDR:
31133 1714 do_add(false);
31134 1714 break;
31135
31136 case SUBV:
31137 114 do_sub(true);
31138 114 break;
31139 case SUBV2:
31140 6 do_sub(true,true);
31141 6 break;
31142
31143 case SUBR:
31144 432 do_sub(false);
31145 432 break;
31146
31147 case MULTV:
31148 do_mult(true);
31149 break;
31150
31151 case MULTR:
31152 564 do_mult(false);
31153 564 break;
31154
31155 case DIVV:
31156 do_div(true);
31157 break;
31158 case DIVV2:
31159 do_div(true,true);
31160 break;
31161
31162 case DIVR:
31163 7 do_div(false);
31164 7 break;
31165
31166 case MODV:
31167 do_mod(true);
31168 break;
31169 case MODV2:
31170 do_mod(true,true);
31171 break;
31172
31173 case MODR:
31174 415 do_mod(false);
31175 415 break;
31176
31177 case SINV:
31178 do_trig(true, 0);
31179 break;
31180
31181 case SINR:
31182 9550421 do_trig(false, 0);
31183 9550421 break;
31184
31185 case COSV:
31186 do_trig(true, 1);
31187 break;
31188
31189 case COSR:
31190 6483138 do_trig(false, 1);
31191 6483138 break;
31192
31193 case TANV:
31194 do_trig(true, 2);
31195 break;
31196
31197 case TANR:
31198 100 do_trig(false, 2);
31199 100 break;
31200
31201 case DEGTORAD:
31202 1480 do_degtorad();
31203 1480 break;
31204
31205 case RADTODEG:
31206 138537 do_radtodeg();
31207 138537 break;
31208
31209 case STRINGLENGTH:
31210 6048 FFCore.do_strlen(false);
31211 6048 break;
31212
31213 case ARCSINR:
31214 14918 do_asin(false);
31215 14918 break;
31216
31217 case ARCCOSR:
31218 do_acos(false);
31219 break;
31220
31221 case ARCTANR:
31222 5879938 do_arctan();
31223 5879938 break;
31224
31225 //Text ptr functions
31226 case FONTHEIGHTR:
31227 6352 do_fontheight();
31228 6352 break;
31229 case STRINGWIDTHR:
31230 17821 do_strwidth();
31231 17821 break;
31232 case CHARWIDTHR:
31233 37547 do_charwidth();
31234 37547 break;
31235 case MESSAGEWIDTHR:
31236 ri->d[rEXP1] = 10000* do_msgwidth(get_register(sarg1)/10000);
31237 break;
31238 case MESSAGEHEIGHTR:
31239 ri->d[rEXP1] = 10000* do_msgheight(get_register(sarg1)/10000);
31240 break;
31241 //
31242
31243 case COMBO_AT:
31244 {
31245 499288 int32_t x = get_register(sarg1) / 10000;
31246 499288 int32_t y = get_register(sarg2) / 10000;
31247 499288 x = std::clamp(x, 0, world_w - 1);
31248 499288 y = std::clamp(y, 0, world_h - 1);
31249 499288 set_register(sarg1, (int)COMBOPOS_REGION(x, y) * 10000);
31250 499288 break;
31251 }
31252
31253 case COMBO_ADJUST:
31254 {
31255 16 rpos_t rpos = (rpos_t)(get_register(sarg1) / 10000);
31256
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if (!is_valid_rpos(rpos))
31257 {
31258 set_register(sarg1, -1);
31259 break;
31260 }
31261
31262 144 auto [x, y] = COMBOXY_REGION(rpos);
31263 32 x += get_register(sarg2) / 10000;
31264 32 y += get_register(sarg3) / 10000;
31265 32 x = std::clamp(x, 0, world_w - 1);
31266 32 y = std::clamp(y, 0, world_h - 1);
31267 48 set_register(sarg1, (int)COMBOPOS_REGION(x, y) * 10000);
31268 16 break;
31269 }
31270
31271 //String.h functions 2.55 Alpha 23
31272 2541 case STRINGCOMPARE: FFCore.do_strcmp(); break;
31273 case STRINGICOMPARE: FFCore.do_stricmp(); break;
31274 2925 case STRINGCOPY: FFCore.do_strcpy(false,false); break;
31275 1 case ARRAYCOPY: FFCore.do_arraycpy(false,false); break;
31276 case STRINGNCOMPARE: FFCore.do_strncmp(); break;
31277 case STRINGNICOMPARE: FFCore.do_strnicmp(); break;
31278
31279 //More string.h functions, 19th May, 2019
31280 case XLEN: FFCore.do_xlen(false); break;
31281 case XTOI: FFCore.do_xtoi(false); break;
31282 case ILEN: FFCore.do_ilen(false); break;
31283 case ATOI: FFCore.do_atoi(false); break;
31284 case ATOL: FFCore.do_atol(false); break;
31285 case STRCSPN: FFCore.do_strcspn(); break;
31286 case STRSTR: FFCore.do_strstr(); break;
31287 14 case XTOA: FFCore.do_xtoa(); break;
31288 4797 case ITOA: FFCore.do_itoa(); break;
31289 56 case ITOACAT: FFCore.do_itoacat(); break;
31290 935 case STRCAT: FFCore.do_strcat(); break;
31291 case STRSPN: FFCore.do_strspn(); break;
31292 case STRCHR: FFCore.do_strchr(); break;
31293 case STRRCHR: FFCore.do_strrchr(); break;
31294 case XLEN2: FFCore.do_xlen2(); break;
31295 case XTOI2: FFCore.do_xtoi2(); break;
31296 case ILEN2: FFCore.do_ilen2(); break;
31297 case ATOI2: FFCore.do_atoi2(); break;
31298 case REMCHR2: FFCore.do_remchr2(); break;
31299 case UPPERTOLOWER: FFCore.do_UpperToLower(false); break;
31300 1 case LOWERTOUPPER: FFCore.do_LowerToUpper(false); break;
31301 case CONVERTCASE: FFCore.do_ConvertCase(false); break;
31302
31303 case GETNPCSCRIPT: FFCore.do_getnpcscript(); break;
31304 case GETCOMBOSCRIPT: FFCore.do_getcomboscript(); break;
31305 1707 case GETLWEAPONSCRIPT: FFCore.do_getlweaponscript(); break;
31306 1664 case GETEWEAPONSCRIPT: FFCore.do_geteweaponscript(); break;
31307 case GETHEROSCRIPT: FFCore.do_getheroscript(); break;
31308 137106 case GETGENERICSCRIPT: FFCore.do_getgenericscript(); break;
31309 case GETGLOBALSCRIPT: FFCore.do_getglobalscript(); break;
31310 105 case GETDMAPSCRIPT: FFCore.do_getdmapscript(); break;
31311 case GETSCREENSCRIPT: FFCore.do_getscreenscript(); break;
31312 31 case GETSPRITESCRIPT: FFCore.do_getitemspritescript(); break;
31313 case GETUNTYPEDSCRIPT: FFCore.do_getuntypedscript(); break;
31314 case GETSUBSCREENSCRIPT:FFCore.do_getsubscreenscript(); break;
31315 case GETNPCBYNAME: FFCore.do_getnpcbyname(); break;
31316 case GETITEMBYNAME: FFCore.do_getitembyname(); break;
31317 case GETCOMBOBYNAME: FFCore.do_getcombobyname(); break;
31318 case GETDMAPBYNAME: FFCore.do_getdmapbyname(); break;
31319
31320 case ABS:
31321 do_abs(false);
31322 break;
31323
31324 case MINR:
31325 do_min(false);
31326 break;
31327
31328 case MINV:
31329 do_min(true);
31330 break;
31331
31332 case MAXR:
31333 do_max(false);
31334 break;
31335 case MAXV:
31336 do_max(true);
31337 break;
31338 case WRAPRADIANS:
31339 do_wrap_rad(false);
31340 break;
31341 case WRAPDEGREES:
31342 2397 do_wrap_deg(false);
31343 2397 break;
31344
31345 case MAXVARG:
31346 1520226 FFCore.do_varg_max();
31347 1520226 break;
31348 case MINVARG:
31349 140579 FFCore.do_varg_min();
31350 140579 break;
31351 case CHOOSEVARG:
31352 5 FFCore.do_varg_choose();
31353 5 break;
31354 case MAKEVARGARRAY:
31355 28 FFCore.do_varg_makearray(type,i);
31356 28 break;
31357
31358 case PUSHVARGV:
31359 1649928 do_push_varg(true);
31360 1649928 break;
31361 case PUSHVARGR:
31362 1731172 do_push_varg(false);
31363 1731172 break;
31364 case PUSHVARGSV:
31365 2674 do_push_vargs(true);
31366 2674 break;
31367 case PUSHVARGSR:
31368 do_push_vargs(false);
31369 break;
31370
31371 case RNDR:
31372 2912197 do_rnd(false);
31373 2912197 break;
31374
31375 case RNDV:
31376 do_rnd(true);
31377 break;
31378
31379 case SRNDR:
31380 do_srnd(false);
31381 break;
31382
31383 case SRNDV:
31384 do_srnd(true);
31385 break;
31386
31387 case SRNDRND:
31388 do_srndrnd();
31389 break;
31390
31391 case GETRTCTIMER:
31392 15 FFCore.getRTC(false);
31393 15 break;
31394 case GETRTCTIMEV:
31395 FFCore.getRTC(true);
31396 break;
31397
31398 case FACTORIAL:
31399 do_factorial(false);
31400 break;
31401
31402 case SQROOTV:
31403 do_sqroot(true);
31404 break;
31405
31406 case SQROOTR:
31407 10089782 do_sqroot(false);
31408 10089782 break;
31409
31410 case POWERR:
31411 6556 do_power(false);
31412 6556 break;
31413 case POWERV:
31414 do_power(true);
31415 break;
31416 case POWERV2:
31417 do_power(true,true);
31418 break;
31419
31420 case LPOWERR:
31421 do_lpower(false);
31422 break;
31423 case LPOWERV:
31424 do_lpower(true);
31425 break;
31426 case LPOWERV2:
31427 do_lpower(true,true);
31428 break;
31429
31430 case IPOWERR:
31431 do_ipower(false);
31432 break;
31433
31434 case IPOWERV:
31435 do_ipower(true);
31436 break;
31437
31438 case LOG10:
31439 969 do_log10(false);
31440 969 break;
31441
31442 case LOGE:
31443 648 do_naturallog(false);
31444 648 break;
31445
31446 case ANDR:
31447 1 do_and(false);
31448 1 break;
31449
31450 case ANDV:
31451 do_and(true);
31452 break;
31453
31454 case ORR:
31455 8299299 do_or(false);
31456 8299299 break;
31457
31458 case ORV:
31459 1137746 do_or(true);
31460 1137746 break;
31461
31462 case XORR:
31463 678025 do_xor(false);
31464 678025 break;
31465
31466 case XORV:
31467 243283 do_xor(true);
31468 243283 break;
31469
31470 case NANDR:
31471 do_nand(false);
31472 break;
31473
31474 case NANDV:
31475 do_nand(true);
31476 break;
31477
31478 case NORR:
31479 do_nor(false);
31480 break;
31481
31482 case NORV:
31483 do_nor(true);
31484 break;
31485
31486 case XNORR:
31487 do_xnor(false);
31488 break;
31489
31490 case XNORV:
31491 do_xnor(true);
31492 break;
31493
31494 case BITNOT:
31495 3709786 do_bitwisenot(false);
31496 3709786 break;
31497
31498 case LSHIFTR:
31499 73964923 do_lshift(false);
31500 73964923 break;
31501
31502 case LSHIFTV:
31503 2751879 do_lshift(true);
31504 2751879 break;
31505
31506 case RSHIFTR:
31507 26716589 do_rshift(false);
31508 26716589 break;
31509
31510 case RSHIFTV:
31511 4677945 do_rshift(true);
31512 4677945 break;
31513
31514 case ANDR32:
31515 34306 do_and32(false);
31516 34306 break;
31517
31518 case ANDV32:
31519 10744 do_and32(true);
31520 10744 break;
31521
31522 case ORR32:
31523 17 do_or32(false);
31524 17 break;
31525
31526 case ORV32:
31527 do_or32(true);
31528 break;
31529
31530 case XORR32:
31531 do_xor32(false);
31532 break;
31533
31534 case XORV32:
31535 do_xor32(true);
31536 break;
31537
31538 case BITNOT32:
31539 do_bitwisenot32(false);
31540 break;
31541
31542 case LSHIFTR32:
31543 22 do_lshift32(false);
31544 22 break;
31545
31546 case LSHIFTV32:
31547 do_lshift32(true);
31548 break;
31549
31550 case RSHIFTR32:
31551 34296 do_rshift32(false);
31552 34296 break;
31553
31554 case RSHIFTV32:
31555 do_rshift32(true);
31556 break;
31557
31558 case TRACER:
31559 10283 FFCore.do_trace(false);
31560 10283 break;
31561
31562 case TRACELR:
31563 FFCore.do_tracel(false);
31564 break;
31565
31566 case TRACEV:
31567 34 FFCore.do_trace(true);
31568 34 break;
31569
31570 case TRACE2R:
31571 FFCore.do_tracebool(false);
31572 break;
31573
31574 //Zap and Wavy Effects
31575 case FXWAVYR:
31576 FFCore.do_fx_wavy(false);
31577 break;
31578 case FXZAPR:
31579 FFCore.do_fx_zap(false);
31580 break;
31581 //Zap and Wavy Effects
31582 case FXWAVYV:
31583 FFCore.do_fx_wavy(true);
31584 break;
31585 case FXZAPV:
31586 FFCore.do_fx_zap(true);
31587 break;
31588 case GREYSCALER:
31589 FFCore.do_greyscale(false);
31590 break;
31591 case GREYSCALEV:
31592 FFCore.do_greyscale(true);
31593 break;
31594 case MONOCHROMER:
31595 FFCore.do_monochromatic(false);
31596 break;
31597 case MONOCHROMEV:
31598 FFCore.do_monochromatic(true);
31599 break;
31600
31601 case TRACE2V:
31602 FFCore.do_tracebool(true);
31603 break;
31604
31605 case TRACE3:
31606 FFCore.do_tracenl();
31607 break;
31608
31609 case TRACE4:
31610 2 FFCore.do_cleartrace();
31611 2 break;
31612
31613 case TRACE5:
31614 3 FFCore.do_tracetobase();
31615 3 break;
31616
31617 case TRACE6:
31618 1361 FFCore.do_tracestring();
31619 1361 break;
31620
31621 case PRINTFV:
31622 287 FFCore.do_printf(true, false);
31623 287 break;
31624 case SPRINTFV:
31625 11645 FFCore.do_sprintf(true, false);
31626 11645 break;
31627
31628 case PRINTFVARG:
31629 33469 FFCore.do_printf(true, true);
31630 33469 break;
31631 case SPRINTFVARG:
31632 319 FFCore.do_sprintf(true, true);
31633 319 break;
31634 case PRINTFA:
31635 FFCore.do_printfarr();
31636 break;
31637 case SPRINTFA:
31638 FFCore.do_sprintfarr();
31639 break;
31640 case ARRAYPUSH:
31641 {
31642 2 auto ptr = SH::read_stack(ri->sp + 2) / 10000;
31643 2 auto val = SH::read_stack(ri->sp + 1);
31644 2 auto indx = SH::read_stack(ri->sp + 0) / 10000;
31645 2 ArrayManager am(ptr);
31646 2 ri->d[rEXP1] = am.push(val,indx) ? 10000 : 0;
31647 2 break;
31648 }
31649 case ARRAYPOP:
31650 {
31651 2 auto ptr = SH::read_stack(ri->sp + 1) / 10000;
31652 2 auto indx = SH::read_stack(ri->sp + 0) / 10000;
31653 2 ArrayManager am(ptr);
31654 2 ri->d[rEXP1] = am.pop(indx);
31655 2 break;
31656 }
31657
31658 case BREAKPOINT:
31659 FFCore.do_breakpoint();
31660 break;
31661
31662 case WARP:
31663 do_warp(true);
31664 break;
31665
31666 case WARPR:
31667 107 do_warp(false);
31668 107 break;
31669
31670 case PITWARP:
31671 do_pitwarp(true);
31672 break;
31673
31674 case PITWARPR:
31675 127 do_pitwarp(false);
31676 127 break;
31677
31678 case SELECTAWPNV:
31679 do_selectweapon(true, 1);
31680 break;
31681
31682 case SELECTAWPNR:
31683 5660 do_selectweapon(false, 1);
31684 5660 break;
31685
31686 case SELECTBWPNV:
31687 do_selectweapon(true, 0);
31688 break;
31689
31690 case SELECTBWPNR:
31691 5436 do_selectweapon(false, 0);
31692 5436 break;
31693
31694 case SELECTXWPNR:
31695 do_selectweapon(false, 2);
31696 break;
31697
31698 case SELECTYWPNR:
31699 do_selectweapon(false, 3);
31700 break;
31701
31702 case PLAYSOUNDR:
31703 339164 do_sfx(false);
31704 339164 break;
31705
31706 case PLAYSOUNDV:
31707 do_sfx(true);
31708 break;
31709
31710 case ADJUSTSFXVOLUMER: FFCore.do_adjustsfxvolume(false); break;
31711 case ADJUSTSFXVOLUMEV: FFCore.do_adjustsfxvolume(true); break;
31712 2004 case ADJUSTVOLUMER: FFCore.do_adjustvolume(false); break;
31713 case ADJUSTVOLUMEV: FFCore.do_adjustvolume(true); break;
31714
31715 case TRIGGERSECRETR:
31716 FFScript::do_triggersecret(false);
31717 break;
31718
31719 case TRIGGERSECRETV:
31720 FFScript::do_triggersecret(true);
31721 break;
31722
31723 case PLAYMIDIR:
31724 63829 do_midi(false);
31725 63829 break;
31726
31727 case PLAYMIDIV:
31728 do_midi(true);
31729 break;
31730
31731 case PLAYENHMUSIC:
31732 178 do_enh_music(false);
31733 178 break;
31734
31735 case GETMUSICFILE:
31736 236 do_get_enh_music_filename(false);
31737 236 break;
31738
31739 case GETMUSICTRACK:
31740 140 do_get_enh_music_track(false);
31741 140 break;
31742
31743 case SETDMAPENHMUSIC:
31744 3783 do_set_dmap_enh_music(false);
31745 3783 break;
31746
31747 // Audio->
31748
31749 case ENDSOUNDR:
31750 1 stop_sfx(false);
31751 1 break;
31752
31753 case ENDSOUNDV:
31754 stop_sfx(true);
31755 break;
31756
31757 case PAUSESOUNDR:
31758 pause_sfx(false);
31759 break;
31760
31761 case PAUSESOUNDV:
31762 pause_sfx(true);
31763 break;
31764
31765 case RESUMESOUNDR:
31766 resume_sfx(false);
31767 break;
31768
31769 case RESUMESOUNDV:
31770 resume_sfx(true);
31771 break;
31772
31773
31774
31775 case PAUSESFX:
31776 {
31777 int32_t sound = ri->d[rINDEX]/10000;
31778 pause_sfx(sound);
31779
31780 }
31781 break;
31782
31783 case RESUMESFX:
31784 {
31785 int32_t sound = ri->d[rINDEX]/10000;
31786 resume_sfx(sound);
31787 }
31788 break;
31789
31790 case ADJUSTSFX:
31791 {
31792 do_sfx_ex(false);
31793 }
31794 break;
31795
31796 case PLAYSOUNDEX:
31797 {
31798 14 do_sfx_ex(true);
31799 }
31800 14 break;
31801
31802 case GETSFXCOMPLETION:
31803 {
31804 do_get_sfx_completion();
31805 }
31806 break;
31807
31808 case CONTINUESFX:
31809 {
31810 int32_t sound = ri->d[rINDEX]/10000;
31811 //Backend::sfx->cont_sfx(sound);
31812
31813 //! cont_sfx was not ported to the new back end!!!
31814 // I believe this restarted the loop.
31815 resume_sfx(sound);
31816 //What was the old instruction, again? Did it exist? -Z
31817 //continue_sfx(sound);
31818 }
31819 break;
31820
31821
31822 /*
31823 case STOPITEMSOUND:
31824 void stop_item_sfx(int32_t family)
31825 */
31826
31827 // Note: these have never worked.
31828 case PAUSEMUSIC:
31829 //What was the instruction prior to adding backends?
31830 //! The pauseAll() function pauses sfx, not music, so this instruction is not doing what I intended. -Z
31831 //Check AllOff() -Z
31832 //zcmusic_pause(ZCMUSIC* zcm, int32_t pause); is in zcmusic.h
31833 // midi_paused = true;
31834 //pause_all_sfx();
31835
31836 //Backend::sfx->pauseAll();
31837 break;
31838 case RESUMEMUSIC:
31839 //What was the instruction prior to adding backends?
31840 //Check AllOff() -Z
31841 //resume_all_sfx();
31842 // midi_paused = false;
31843 //Backend::sfx->resumeAll();
31844 break;
31845
31846 case MSGSTRR:
31847 1117 do_message(false);
31848 1117 break;
31849
31850 case MSGSTRV:
31851 do_message(true);
31852 break;
31853
31854 case ITEMNAME:
31855 2768 do_getitemname();
31856 2768 break;
31857
31858 case LOADLWEAPONR:
31859 1452537 do_loadlweapon(false);
31860 1452537 break;
31861
31862 case LOADLWEAPONV:
31863 do_loadlweapon(true);
31864 break;
31865
31866 case LOADEWEAPONR:
31867 4712414 do_loadeweapon(false);
31868 4712414 break;
31869
31870 case LOADEWEAPONV:
31871 do_loadeweapon(true);
31872 break;
31873
31874 case LOADITEMR:
31875 585769 do_loaditem(false);
31876 585769 break;
31877
31878 case LOADITEMV:
31879 do_loaditem(true);
31880 break;
31881
31882 case LOADITEMDATAR:
31883 5620654 do_loaditemdata(false);
31884 5620654 break;
31885
31886 //New Datatypes
31887 case LOADSHOPR:
31888 FFScript::do_loadshopdata(false);
31889 break;
31890 case LOADSHOPV:
31891 FFScript::do_loadshopdata(true);
31892 break;
31893
31894 case LOADINFOSHOPR:
31895 FFScript::do_loadinfoshopdata(false);
31896 break;
31897 case LOADINFOSHOPV:
31898 FFScript::do_loadinfoshopdata(true);
31899 break;
31900 case LOADNPCDATAR:
31901 6365 FFScript::do_loadnpcdata(false);
31902 6365 break;
31903 case LOADNPCDATAV:
31904 FFScript::do_loadnpcdata(true);
31905 break;
31906
31907 case LOADCOMBODATAR:
31908 432438 FFScript::do_loadcombodata(false);
31909 432438 break;
31910 case LOADCOMBODATAV:
31911 FFScript::do_loadcombodata(true);
31912 break;
31913
31914 case LOADTMPSCR:
31915 3209685 FFScript::do_loadmapdata_tempscr(false);
31916 3209685 break;
31917 case LOADTMPSCR2:
31918 FFScript::do_loadmapdata_tempscr2(false);
31919 break;
31920 case REGION_LOAD_TMPSCR_FOR_LAYER_COMBO_POS:
31921 do_loadtmpscrforcombopos(false);
31922 break;
31923 case LOADSCROLLSCR:
31924 177544 FFScript::do_loadmapdata_scrollscr(false);
31925 177544 break;
31926 case LOADSCROLLSCR2:
31927 FFScript::do_loadmapdata_scrollscr2(false);
31928 break;
31929
31930 case LOADSPRITEDATAR:
31931 16 FFScript::do_loadspritedata(false);
31932 16 break;
31933 case LOADSPRITEDATAV:
31934 FFScript::do_loadspritedata(true);
31935 break;
31936
31937 case LOADBITMAPDATAR:
31938 8 FFScript::do_loadbitmapid(false);
31939 8 break;
31940
31941
31942 case LOADBITMAPDATAV:
31943 FFScript::do_loadbitmapid(true);
31944 break;
31945
31946 //functions
31947 case LOADDIRECTORYR:
31948 FFCore.do_loaddirectory(); break;
31949 case CREATEPALDATA:
31950 223 FFCore.do_create_paldata(); break;
31951 case CREATEPALDATACLR:
31952 11 FFCore.do_create_paldata_clr(); break;
31953 case MIXCLR:
31954 FFCore.do_mix_clr(); break;
31955 case CREATERGBHEX:
31956 FFCore.do_create_rgb_hex(); break;
31957 case CREATERGB:
31958 11 FFCore.do_create_rgb(); break;
31959 case CONVERTFROMRGB:
31960 FFCore.do_convert_from_rgb(); break;
31961 case CONVERTTORGB:
31962 FFCore.do_convert_to_rgb(); break;
31963 case PALDATALOADLEVEL:
31964 24 FFCore.do_paldata_load_level(); break;
31965 case PALDATALOADSPRITE:
31966 87 FFCore.do_paldata_load_sprite(); break;
31967 case PALDATALOADMAIN:
31968 92 FFCore.do_paldata_load_main(); break;
31969 case PALDATALOADCYCLE:
31970 FFCore.do_paldata_load_cycle(); break;
31971 case PALDATALOADBITMAP:
31972 FFCore.do_paldata_load_bitmap(); break;
31973 case PALDATAWRITELEVEL:
31974 370 FFCore.do_paldata_write_level(); break;
31975 case PALDATAWRITELEVELCS:
31976 FFCore.do_paldata_write_levelcset(); break;
31977 case PALDATAWRITESPRITE:
31978 31 FFCore.do_paldata_write_sprite(); break;
31979 case PALDATAWRITESPRITECS:
31980 FFCore.do_paldata_write_spritecset(); break;
31981 case PALDATAWRITEMAIN:
31982 1064 FFCore.do_paldata_write_main(); break;
31983 case PALDATAWRITEMAINCS:
31984 130 FFCore.do_paldata_write_maincset(); break;
31985 case PALDATAWRITECYCLE:
31986 FFCore.do_paldata_write_cycle(); break;
31987 case PALDATAWRITECYCLECS:
31988 FFCore.do_paldata_write_cyclecset(); break;
31989 case PALDATAVALIDCLR:
31990 FFCore.do_paldata_colorvalid(); break;
31991 case PALDATACLEARCLR:
31992 FFCore.do_paldata_clearcolor(); break;
31993 case PALDATACLEARCSET:
31994 FFCore.do_paldata_clearcset(); break;
31995 case PALDATAMIX:
31996 450 FFCore.do_paldata_mix(); break;
31997 case PALDATAMIXCS:
31998 4781 FFCore.do_paldata_mixcset(); break;
31999 case PALDATACOPY:
32000 FFCore.do_paldata_copy(); break;
32001 case PALDATACOPYCSET:
32002 112 FFCore.do_paldata_copycset(); break;
32003 case PALDATAFREE:
32004
1/2
✓ Branch 0 taken 234 times.
✗ Branch 1 not taken.
234 if (user_paldata* pd = checkPalData(ri->paldataref, true))
32005 {
32006 234 free_script_object(pd->id);
32007 234 }
32008 234 break;
32009 case PALDATAOWN:
32010 if (user_paldata* pd = checkPalData(ri->paldataref, false))
32011 {
32012 own_script_object(pd, type, i);
32013 }
32014 break;
32015 case LOADRNG: //command
32016 628 FFCore.do_loadrng(); break;
32017
32018 case ITEMGETDISPLAYNAME: //command
32019 53 item_display_name(false); break;
32020 case ITEMSETDISPLAYNAME: //command
32021 item_display_name(true); break;
32022 case ITEMGETSHOWNNAME: //command
32023 item_shown_name(); break;
32024
32025 case DMAPDATAGETNAMER: //command
32026 FFScript::do_getDMapData_dmapname(false); break;
32027 case DMAPDATAGETNAMEV: //command
32028 FFScript::do_getDMapData_dmapname(true); break;
32029
32030 case DMAPDATASETNAMER: //command
32031 FFScript::do_setDMapData_dmapname(false); break;
32032 case DMAPDATASETNAMEV: //command
32033 FFScript::do_setDMapData_dmapname(true); break;
32034
32035
32036
32037 case DMAPDATAGETTITLER: //command
32038 FFScript::do_getDMapData_dmaptitle(false); break;
32039 case DMAPDATAGETTITLEV: //command
32040 FFScript::do_getDMapData_dmaptitle(true); break;
32041 case DMAPDATASETTITLER: //command
32042 FFScript::do_setDMapData_dmaptitle(false); break;
32043 case DMAPDATASETTITLEV: //command
32044 FFScript::do_setDMapData_dmaptitle(true); break;
32045
32046
32047 case DMAPDATAGETINTROR: //command
32048 FFScript::do_getDMapData_dmapintro(false); break;
32049 case DMAPDATAGETINTROV: //command
32050 FFScript::do_getDMapData_dmapintro(true); break;
32051 case DMAPDATANSETITROR: //command
32052 FFScript::do_setDMapData_dmapintro(false); break;
32053 case DMAPDATASETINTROV: //command
32054 FFScript::do_setDMapData_dmapintro(true); break;
32055
32056
32057 case DMAPDATAGETMUSICR: //command, string to load a music file
32058 FFScript::do_getDMapData_music(false); break;
32059 case DMAPDATAGETMUSICV: //command, string to load a music file
32060 FFScript::do_getDMapData_music(true); break;
32061 case DMAPDATASETMUSICR: //command, string to load a music file
32062 FFScript::do_setDMapData_music(false); break;
32063 case DMAPDATASETMUSICV: //command, string to load a music file
32064 FFScript::do_setDMapData_music(true); break;
32065
32066 case LOADMESSAGEDATAR: //COMMAND
32067 24 FFScript::do_loadmessagedata(false);
32068 24 break;
32069 case LOADMESSAGEDATAV: //COMMAND
32070 FFScript::do_loadmessagedata(false);
32071 break;
32072
32073
32074 case MESSAGEDATASETSTRINGR: //command
32075 24 FFScript::do_messagedata_setstring(false);
32076 24 break;
32077 case MESSAGEDATASETSTRINGV: //command
32078 FFScript::do_messagedata_setstring(false);
32079 break;
32080
32081 case MESSAGEDATAGETSTRINGR: //command
32082 FFScript::do_messagedata_getstring(false);
32083 break;
32084 case MESSAGEDATAGETSTRINGV: //command
32085 FFScript::do_messagedata_getstring(false);
32086 break;
32087 case LOADITEMDATAV:
32088 do_loaditemdata(true);
32089 break;
32090
32091 case LOADNPCBYSUID:
32092 12 FFCore.do_loadnpc_by_script_uid(false);
32093 12 break;
32094
32095 case LOADLWEAPONBYSUID:
32096 598 FFCore.do_loadlweapon_by_script_uid(false);
32097 598 break;
32098
32099 case LOADWEAPONCBYSUID:
32100 FFCore.do_loadeweapon_by_script_uid(false);
32101 break;
32102
32103 case LOADNPCR:
32104 27870027 do_loadnpc(false);
32105 27870027 break;
32106
32107 case LOADNPCV:
32108 do_loadnpc(true);
32109 break;
32110
32111 case CREATELWEAPONR:
32112 87667 do_createlweapon(false);
32113 87667 break;
32114
32115 case CREATELWEAPONV:
32116 do_createlweapon(true);
32117 break;
32118
32119 case CREATEEWEAPONR:
32120 209493 do_createeweapon(false);
32121 209493 break;
32122
32123 case CREATEEWEAPONV:
32124 do_createeweapon(true);
32125 break;
32126
32127 case CREATEITEMR:
32128 22443 do_createitem(false);
32129 22443 break;
32130
32131 case CREATEITEMV:
32132 do_createitem(true);
32133 break;
32134
32135 case CREATENPCR:
32136 3530 do_createnpc(false);
32137 3530 break;
32138
32139 case CREATENPCV:
32140 do_createnpc(true);
32141 break;
32142
32143 case ISVALIDARRAY:
32144 573 do_isvalidarray();
32145 573 break;
32146
32147 case ISVALIDITEM:
32148 31487 do_isvaliditem();
32149 31487 break;
32150
32151 case ISVALIDBITMAP:
32152 5 FFCore.do_isvalidbitmap();
32153 5 break;
32154
32155 case ISALLOCATEDBITMAP:
32156 43 FFCore.do_isallocatedbitmap();
32157 43 break;
32158
32159 case ISVALIDNPC:
32160 11754119 do_isvalidnpc();
32161 11754119 break;
32162
32163 case ISVALIDLWPN:
32164 1205956 do_isvalidlwpn();
32165 1205956 break;
32166
32167 case ISVALIDEWPN:
32168 160009 do_isvalidewpn();
32169 160009 break;
32170
32171 case LWPNMAKEANGULAR:
32172 do_lwpnmakeangular();
32173 break;
32174
32175 case EWPNMAKEANGULAR:
32176 do_ewpnmakeangular();
32177 break;
32178
32179 case LWPNMAKEDIRECTIONAL:
32180 do_lwpnmakedirectional();
32181 break;
32182
32183 case EWPNMAKEDIRECTIONAL:
32184 do_ewpnmakedirectional();
32185 break;
32186
32187 case LWPNUSESPRITER:
32188 19653 do_lwpnusesprite(false);
32189 19653 break;
32190
32191 case LWPNUSESPRITEV:
32192 do_lwpnusesprite(true);
32193 break;
32194
32195 case EWPNUSESPRITER:
32196 208946 do_ewpnusesprite(false);
32197 208946 break;
32198
32199 case EWPNUSESPRITEV:
32200 do_ewpnusesprite(true);
32201 break;
32202
32203 case CLEARSPRITESR:
32204 do_clearsprites(false);
32205 break;
32206
32207 case CLEARSPRITESV:
32208 do_clearsprites(true);
32209 break;
32210
32211 case ISSOLID:
32212 21032557 do_issolid();
32213 21032557 break;
32214
32215 case MAPDATAISSOLID:
32216 do_mapdataissolid();
32217 break;
32218
32219 case MAPDATAISSOLIDLYR:
32220 do_mapdataissolid_layer();
32221 break;
32222
32223 case ISSOLIDLAYER:
32224 do_issolid_layer();
32225 break;
32226
32227 case SETSIDEWARP:
32228 257 do_setsidewarp();
32229 257 break;
32230
32231 case SETTILEWARP:
32232 5 do_settilewarp();
32233 5 break;
32234
32235 case GETSIDEWARPDMAP:
32236 354947 do_getsidewarpdmap(false);
32237 354947 break;
32238
32239 case GETSIDEWARPSCR:
32240 3 do_getsidewarpscr(false);
32241 3 break;
32242
32243 case GETSIDEWARPTYPE:
32244 do_getsidewarptype(false);
32245 break;
32246
32247 case GETTILEWARPDMAP:
32248 354994 do_gettilewarpdmap(false);
32249 354994 break;
32250
32251 case GETTILEWARPSCR:
32252 50 do_gettilewarpscr(false);
32253 50 break;
32254
32255 case GETTILEWARPTYPE:
32256 3 do_gettilewarptype(false);
32257 3 break;
32258
32259 case LAYERSCREEN:
32260 13670631 do_layerscreen();
32261 13670631 break;
32262
32263 case LAYERMAP:
32264 18282859 do_layermap();
32265 18282859 break;
32266
32267 case SECRETS:
32268 357 do_triggersecrets(ri->screenref);
32269 357 break;
32270
32271 case REGION_TRIGGER_SECRETS:
32272 {
32273 118 int screen = get_register(sarg1) / 10000;
32274
1/2
✓ Branch 0 taken 118 times.
✗ Branch 1 not taken.
118 if (!is_in_current_region(screen))
32275 {
32276 scripting_log_error_with_context("Must use a screen in the current region. got: {}", screen);
32277 break;
32278 }
32279
32280 118 do_triggersecrets(screen);
32281 118 break;
32282 }
32283
32284 case GRAPHICSGETPIXEL:
32285 FFCore.do_graphics_getpixel();
32286 break;
32287 case GRAPHICSCOUNTCOLOR:
32288 FFCore.do_bmpcollision();
32289 break;
32290
32291 case COMBOTILE:
32292 3062 do_combotile(false);
32293 3062 break;
32294
32295 case DRAWLIGHT_CIRCLE:
32296 {
32297 if (get_qr(qr_SCRIPTS_SCREEN_DRAW_LIGHT_NO_OFFSET))
32298 {
32299 static const int ARGS = 7;
32300 zfix cx = zslongToFix(SH::read_stack(ri->sp + (ARGS-1)));
32301 zfix cy = zslongToFix(SH::read_stack(ri->sp + (ARGS-2)));
32302 int radius = SH::read_stack(ri->sp + (ARGS-3));
32303 int transp_rad = SH::read_stack(ri->sp + (ARGS-4));
32304 int dith_rad = SH::read_stack(ri->sp + (ARGS-5));
32305 int dith_type = SH::read_stack(ri->sp + (ARGS-6));
32306 int dith_arg = SH::read_stack(ri->sp + (ARGS-7));
32307 if(radius >= 0) radius /= 10000;
32308 else radius = game->get_light_rad();
32309 if(!radius) break;
32310 if(transp_rad >= 0) transp_rad /= 10000;
32311 if(dith_rad >= 0) dith_rad /= 10000;
32312 if(dith_type >= 0) dith_type /= 10000;
32313 if(dith_arg >= 0) dith_arg /= 10000;
32314
32315 doDarkroomCircle(cx,cy,radius,darkscr_bmp,nullptr,dith_rad,transp_rad,dith_type,dith_arg);
32316 }
32317 else do_drawing_command(scommand, true);
32318
32319 break;
32320 }
32321 case DRAWLIGHT_SQUARE:
32322 {
32323 if (get_qr(qr_SCRIPTS_SCREEN_DRAW_LIGHT_NO_OFFSET))
32324 {
32325 static const int ARGS = 7;
32326 zfix cx = zslongToFix(SH::read_stack(ri->sp + (ARGS-1)));
32327 zfix cy = zslongToFix(SH::read_stack(ri->sp + (ARGS-2)));
32328 int radius = SH::read_stack(ri->sp + (ARGS-3));
32329 int transp_rad = SH::read_stack(ri->sp + (ARGS-4));
32330 int dith_rad = SH::read_stack(ri->sp + (ARGS-5));
32331 int dith_type = SH::read_stack(ri->sp + (ARGS-6));
32332 int dith_arg = SH::read_stack(ri->sp + (ARGS-7));
32333 if(radius >= 0) radius /= 10000;
32334 else radius = game->get_light_rad();
32335 if(!radius) break;
32336 if(transp_rad >= 0) transp_rad /= 10000;
32337 if(dith_rad >= 0) dith_rad /= 10000;
32338 if(dith_type >= 0) dith_type /= 10000;
32339 if(dith_arg >= 0) dith_arg /= 10000;
32340
32341 doDarkroomSquare(cx,cy,radius,darkscr_bmp,nullptr,dith_rad,transp_rad,dith_type,dith_arg);
32342 }
32343 else do_drawing_command(scommand, true);
32344
32345 break;
32346 }
32347 case DRAWLIGHT_CONE:
32348 {
32349 if (get_qr(qr_SCRIPTS_SCREEN_DRAW_LIGHT_NO_OFFSET))
32350 {
32351 static const int ARGS = 8;
32352 zfix cx = zslongToFix(SH::read_stack(ri->sp + (ARGS-1)));
32353 zfix cy = zslongToFix(SH::read_stack(ri->sp + (ARGS-2)));
32354 int dir = SH::read_stack(ri->sp + (ARGS-3)) / 10000;
32355 int length = SH::read_stack(ri->sp + (ARGS-4));
32356 int transp_rad = SH::read_stack(ri->sp + (ARGS-5));
32357 int dith_rad = SH::read_stack(ri->sp + (ARGS-6));
32358 int dith_type = SH::read_stack(ri->sp + (ARGS-7));
32359 int dith_arg = SH::read_stack(ri->sp + (ARGS-8));
32360 if(length >= 0) length /= 10000;
32361 else length = game->get_light_rad()*2;
32362 if(!length) break;
32363 if(dir < 0) break;
32364 else dir = NORMAL_DIR(dir);
32365 if(transp_rad >= 0) transp_rad /= 10000;
32366 if(dith_rad >= 0) dith_rad /= 10000;
32367 if(dith_type >= 0) dith_type /= 10000;
32368 if(dith_arg >= 0) dith_arg /= 10000;
32369
32370 doDarkroomCone(cx,cy,length,dir,darkscr_bmp,nullptr,dith_rad,transp_rad,dith_type,dith_arg);
32371 }
32372 else do_drawing_command(scommand, true);
32373
32374 break;
32375 }
32376
32377 case RECTR:
32378 case CIRCLER:
32379 case ARCR:
32380 case ELLIPSER:
32381 case LINER:
32382 case PUTPIXELR:
32383 case PIXELARRAYR:
32384 case TILEARRAYR:
32385 case LINESARRAY:
32386 case COMBOARRAYR:
32387 case DRAWTILER:
32388 case DRAWTILECLOAKEDR:
32389 case DRAWCOMBOR:
32390 case DRAWCOMBOCLOAKEDR:
32391 case DRAWCHARR:
32392 case DRAWINTR:
32393 case QUADR:
32394 case TRIANGLER:
32395 case QUAD3DR:
32396 case TRIANGLE3DR:
32397 case FASTTILER:
32398 case FASTCOMBOR:
32399 case DRAWSTRINGR:
32400 case DRAWSTRINGR2:
32401 case BMPDRAWSTRINGR2:
32402 case SPLINER:
32403 case BITMAPR:
32404 case BITMAPEXR:
32405 case DRAWLAYERR:
32406 case DRAWSCREENR:
32407 case POLYGONR:
32408 case FRAMER:
32409 case TILEBLIT:
32410 case COMBOBLIT:
32411 45321202 do_drawing_command(scommand, true);
32412 45321202 break;
32413
32414 case BMPRECTR:
32415 case BMPCIRCLER:
32416 case BMPARCR:
32417 case BMPELLIPSER:
32418 case BMPLINER:
32419 case BMPSPLINER:
32420 case BMPPUTPIXELR:
32421 case BMPDRAWTILER:
32422 case BMPDRAWTILECLOAKEDR:
32423 case BMPDRAWCOMBOR:
32424 case BMPDRAWCOMBOCLOAKEDR:
32425 case BMPFASTTILER:
32426 case BMPFASTCOMBOR:
32427 case BMPDRAWCHARR:
32428 case BMPDRAWINTR:
32429 case BMPDRAWSTRINGR:
32430 case BMPQUADR:
32431 case BMPQUAD3DR:
32432 case BMPTRIANGLER:
32433 case BMPTRIANGLE3DR:
32434 case BMPPOLYGONR:
32435 case BMPDRAWLAYERR:
32436 case BMPDRAWLAYERSOLIDR:
32437 case BMPDRAWLAYERCFLAGR:
32438 case BMPDRAWLAYERCTYPER:
32439 case BMPDRAWLAYERCIFLAGR:
32440 case BMPDRAWLAYERSOLIDITYR:
32441 case BMPDRAWSCREENR:
32442 case BMPDRAWSCREENSOLIDR:
32443 case BMPDRAWSCREENSOLID2R:
32444 case BMPDRAWSCREENCOMBOFR:
32445 case BMPDRAWSCREENCOMBOIR:
32446 case BMPDRAWSCREENCOMBOTR:
32447 case BITMAPGETPIXEL:
32448 case BMPBLIT:
32449 case BMPBLITTO:
32450 case BMPTILEBLIT:
32451 case BMPCOMBOBLIT:
32452 case BMPMODE7:
32453 case WRITEBITMAP:
32454 case CLEARBITMAP:
32455 case BITMAPCLEARTOCOLOR:
32456 case BMPFRAMER:
32457 case BMPWRITETILE:
32458 case BMPDITHER:
32459 case BMPREPLCOLOR:
32460 case BMPSHIFTCOLOR:
32461 case BMPMASKDRAW:
32462 case BMPMASKDRAW2:
32463 case BMPMASKDRAW3:
32464 case BMPMASKBLIT:
32465 case BMPMASKBLIT2:
32466 case BMPMASKBLIT3:
32467 53638474 do_drawing_command(scommand, false);
32468 53638474 break;
32469 case READBITMAP:
32470 {
32471 uint32_t bitref = SH::read_stack(ri->sp+2);
32472 if(user_bitmap* b = checkBitmap(bitref,false,true))
32473 do_drawing_command(scommand, false);
32474 else //If the pointer isn't allocated, attempt to allocate it first
32475 {
32476 bitref = FFCore.get_free_bitmap();
32477 ri->d[rEXP2] = bitref; //Return to ptr
32478 if(bitref) SH::write_stack(ri->sp+2,bitref); //Write the ref, for the drawing command to read
32479 else break; //No ref allocated; don't enqueue the drawing command.
32480 do_drawing_command(scommand, false);
32481 }
32482 break;
32483 }
32484 case REGENERATEBITMAP:
32485 {
32486 26528 ri->d[rEXP2] = SH::read_stack(ri->sp+3);
32487
1/2
✓ Branch 0 taken 26528 times.
✗ Branch 1 not taken.
26528 if(user_bitmap* b = checkBitmap(ri->d[rEXP2],false,true))
32488 26528 do_drawing_command(scommand, false);
32489 else //If the pointer isn't allocated
32490 {
32491 int32_t w = SH::read_stack(ri->sp) / 10000;
32492 int32_t h = SH::read_stack(ri->sp+1) / 10000;
32493 if ( get_qr(qr_OLDCREATEBITMAP_ARGS) )
32494 {
32495 //flip height and width
32496 h = h ^ w;
32497 w = h ^ w;
32498 h = h ^ w;
32499 }
32500
32501 ri->d[rEXP2] = FFCore.create_user_bitmap_ex(h,w); //Return to ptr
32502 }
32503 26528 break;
32504 }
32505
32506 case BITMAPFREE:
32507 {
32508 3512 FFCore.do_deallocate_bitmap();
32509 3512 break;
32510 }
32511
32512 case BITMAPOWN:
32513 {
32514
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 146 times.
146 if(FFCore.isSystemBitref(ri->bitmapref))
32515 break; //Don't attempt to own system bitmaps!
32516
32517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 146 times.
146 if (auto bitmap = checkBitmap(ri->bitmapref, false))
32518 146 own_script_object(bitmap, type, i);
32519 146 break;
32520 }
32521
32522 case OBJ_OWN_BITMAP:
32523 {
32524 int bmpid = get_register(sarg1);
32525 if(FFCore.isSystemBitref(bmpid))
32526 break; //Don't attempt to own system bitmaps!
32527 user_bitmap* b = checkBitmap(bmpid, false);
32528 if(!b) break;
32529 ScriptType own_type = (ScriptType)sarg2;
32530 int32_t own_i = get_own_i(own_type);
32531 own_script_object(b, own_type, own_i);
32532 break;
32533 }
32534 case OBJ_OWN_PALDATA:
32535 {
32536 int palid = get_register(sarg1);
32537 user_paldata* pd = checkPalData(palid, false);
32538 if(!pd) break;
32539 ScriptType own_type = (ScriptType)sarg2;
32540 int32_t own_i = get_own_i(own_type);
32541 own_script_object(pd, own_type, own_i);
32542 break;
32543 }
32544 case OBJ_OWN_FILE:
32545 {
32546 int fileid = get_register(sarg1);
32547 user_file* f = checkFile(fileid, false);
32548 if(!f) break;
32549 ScriptType own_type = (ScriptType)sarg2;
32550 int32_t own_i = get_own_i(own_type);
32551 own_script_object(f, own_type, own_i);
32552 break;
32553 }
32554 case OBJ_OWN_DIR:
32555 {
32556 int dirid = get_register(sarg1);
32557 user_dir* dr = checkDir(dirid, false);
32558 if(!dr) break;
32559 ScriptType own_type = (ScriptType)sarg2;
32560 int32_t own_i = get_own_i(own_type);
32561 own_script_object(dr, own_type, own_i);
32562 break;
32563 }
32564 case OBJ_OWN_STACK:
32565 {
32566 int stackid = get_register(sarg1);
32567 user_stack* st = checkStack(stackid, false);
32568 if(!st) break;
32569 ScriptType own_type = (ScriptType)sarg2;
32570 int32_t own_i = get_own_i(own_type);
32571 own_script_object(st, own_type, own_i);
32572 break;
32573 }
32574 case OBJ_OWN_RNG:
32575 {
32576 int rngid = get_register(sarg1);
32577 user_rng* r = checkRNG(rngid, false);
32578 if(!r) break;
32579 ScriptType own_type = (ScriptType)sarg2;
32580 int32_t own_i = get_own_i(own_type);
32581 own_script_object(r, own_type, own_i);
32582 break;
32583 }
32584 case OBJ_OWN_ARRAY:
32585 {
32586 int arrid = get_register(sarg1)/10000;
32587 ScriptType own_type = (ScriptType)sarg2;
32588 int32_t own_i = get_own_i(own_type);
32589 do_own_array(arrid, own_type, own_i);
32590 break;
32591 }
32592
32593 case COPYTILEVV:
32594 do_copytile(true, true);
32595 break;
32596
32597 case COPYTILEVR:
32598 do_copytile(true, false);
32599 break;
32600
32601 case COPYTILERV:
32602 do_copytile(false, true);
32603 break;
32604
32605 case COPYTILERR:
32606 49233778 do_copytile(false, false);
32607 49233778 break;
32608
32609 case SWAPTILEVV:
32610 do_swaptile(true, true);
32611 break;
32612
32613 case SWAPTILEVR:
32614 do_swaptile(true, false);
32615 break;
32616
32617 case SWAPTILERV:
32618 do_swaptile(false, true);
32619 break;
32620
32621 case SWAPTILERR:
32622 do_swaptile(false, false);
32623 break;
32624
32625 case CLEARTILEV:
32626 do_cleartile(true);
32627 break;
32628
32629 case CLEARTILER:
32630 10 do_cleartile(false);
32631 10 break;
32632
32633 case OVERLAYTILEVV:
32634 do_overlaytile(true, true);
32635 break;
32636
32637 case OVERLAYTILEVR:
32638 do_overlaytile(true, false);
32639 break;
32640
32641 case OVERLAYTILERV:
32642 do_overlaytile(false, true);
32643 break;
32644
32645 case OVERLAYTILERR:
32646 57032 do_overlaytile(false, false);
32647 57032 break;
32648
32649 case FLIPROTTILEVV:
32650 do_fliprotatetile(true, true);
32651 break;
32652
32653 case FLIPROTTILEVR:
32654 do_fliprotatetile(true, false);
32655 break;
32656
32657 case FLIPROTTILERV:
32658 do_fliprotatetile(false, true);
32659 break;
32660
32661 case FLIPROTTILERR:
32662 do_fliprotatetile(false, false);
32663 break;
32664
32665 case GETTILEPIXEL:
32666 do_gettilepixel();
32667 break;
32668
32669 case SETTILEPIXEL:
32670 do_settilepixel();
32671 break;
32672
32673 case SHIFTTILEVV:
32674 do_shifttile(true, true);
32675 break;
32676
32677 case SHIFTTILEVR:
32678 do_shifttile(true, false);
32679 break;
32680
32681 case SHIFTTILERV:
32682 do_shifttile(false, true);
32683 break;
32684
32685 case SHIFTTILERR:
32686 do_shifttile(false, false);
32687 break;
32688
32689 case SETRENDERTARGET:
32690 7069332 do_set_rendertarget(true);
32691 7069332 break;
32692
32693 case GAMEEND:
32694
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if ( using_SRAM )
32695 {
32696 Z_scripterrlog("Cannot End Game while reading or writing to SRAM. Aborting End. /n");
32697 break;
32698 }
32699 4 Quit = qQUIT;
32700 4 skipcont = 1;
32701 4 scommand = 0xFFFF;
32702 4 break;
32703 case GAMEEXIT:
32704 28 Quit = qEXIT;
32705 28 skipcont = 1;
32706 28 scommand = 0xFFFF;
32707 28 break;
32708 case GAMERELOAD:
32709
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if ( using_SRAM )
32710 {
32711 Z_scripterrlog("Cannot Reload Game while reading or writing to SRAM. Aborting Reload. /n");
32712 break;
32713 }
32714 6 Quit = qRELOAD;
32715 6 skipcont = 1;
32716 6 scommand = 0xFFFF;
32717 6 break;
32718 case GAMESETCUSTOMCURSOR:
32719 {
32720 int32_t bmpptr = SH::read_stack(ri->sp + 4);
32721 int fx = SH::read_stack(ri->sp + 3) / 10000;
32722 int fy = SH::read_stack(ri->sp + 2) / 10000;
32723 bool recolor = SH::read_stack(ri->sp + 1)!=0;
32724 bool scale = SH::read_stack(ri->sp + 0)!=0;
32725 if(user_bitmap* b = checkBitmap(bmpptr,true))
32726 {
32727 custom_mouse(b->u_bmp,fx,fy,recolor,scale);
32728 }
32729 break;
32730 }
32731 case CURRENTITEMID:
32732 {
32733 int ity = SH::read_stack(ri->sp + 1) / 10000;
32734 int flags = SH::read_stack(ri->sp + 0) / 10000;
32735 bool checkcost = flags&0x01;
32736 bool checkjinx = flags&0x02;
32737 bool check_bunny = flags&0x04;
32738 ri->d[rEXP1] = current_item_id(ity,checkcost,checkjinx,check_bunny) * 10000;
32739 break;
32740 }
32741
32742 case GAMECONTINUE:
32743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if ( using_SRAM )
32744 {
32745 Z_scripterrlog("Cannot Continue Game while reading or writing to SRAM. Aborting Continue. /n");
32746 break;
32747 }
32748 2 reset_all_combo_animations();
32749
32750 2 Quit = qCONT;
32751 2 skipcont = 1;
32752 //cont_game();
32753 2 scommand = 0xFFFF;
32754 2 break;
32755
32756 case GAMESAVEQUIT:
32757 if ( using_SRAM )
32758 {
32759 Z_scripterrlog("Cannot Save Game while reading or writing to SRAM. Aborting Save. /n");
32760 break;
32761 }
32762 Quit = qSAVE;
32763 skipcont = 1;
32764 scommand =0xFFFF;
32765 break;
32766
32767 case GAMESAVECONTINUE:
32768 Quit = qSAVECONT;
32769 skipcont = 1;
32770 scommand =0xFFFF;
32771 break;
32772
32773 case SAVE:
32774
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 if ( using_SRAM )
32775 {
32776 Z_scripterrlog("Cannot Save Game while reading or writing to SRAM. Aborting Save. /n");
32777 break;
32778 }
32779
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 if(scriptCanSave)
32780 {
32781 27 save_game(false);
32782 27 scriptCanSave=false;
32783 27 }
32784 27 break;
32785
32786 case SAVESCREEN:
32787 do_showsavescreen();
32788 break;
32789
32790 case SHOWF6SCREEN:
32791 onTryQuit();
32792 break;
32793
32794 case SAVEQUITSCREEN:
32795 save_game(false, 1);
32796 break;
32797
32798 //Not Implemented
32799 case ELLIPSE2:
32800 case FLOODFILL:
32801 break;
32802
32803 case ENQUEUER:
32804 do_enqueue(false);
32805 break;
32806
32807 case ENQUEUEV:
32808 do_enqueue(true);
32809 break;
32810
32811 case DEQUEUE:
32812 do_dequeue(false);
32813 break;
32814
32815 //Visual Effects
32816 case WAVYIN:
32817 FFScript::do_wavyin();
32818 break;
32819 case WAVYOUT:
32820 FFScript::do_wavyout();
32821 break;
32822 case ZAPIN:
32823 FFScript::do_zapin();
32824 break;
32825 case ZAPOUT:
32826 FFScript::do_zapout();
32827 break;
32828 case OPENWIPE:
32829 {
32830 FFScript::do_openscreen();
32831 break;
32832 }
32833 case CLOSEWIPE:
32834 {
32835 FFScript::do_closescreen();
32836 break;
32837 }
32838 case OPENWIPESHAPE:
32839 {
32840 FFScript::do_openscreenshape();
32841 break;
32842 }
32843 case CLOSEWIPESHAPE:
32844 {
32845 FFScript::do_closescreenshape();
32846 break;
32847 }
32848
32849 case TINT:
32850 {
32851 3560 FFCore.Tint();
32852 3560 break;
32853 }
32854
32855 case CLEARTINT:
32856 {
32857 66 FFCore.clearTint();
32858 66 break;
32859 }
32860
32861 case MONOHUE:
32862 {
32863 FFCore.gfxmonohue();
32864 break;
32865 }
32866
32867 case SCREENDOSPAWN:
32868 {
32869 ri->d[rEXP1] = scriptloadenemies(ri->screenref) ? 10000 : 0;
32870 break;
32871 }
32872
32873 case SCRTRIGGERCOMBO:
32874 {
32875 int32_t lyr = get_register(sarg1) / 10000;
32876 int32_t pos = get_register(sarg2) / 10000;
32877 rpos_t rpos = (rpos_t)pos;
32878 if (BC::checkComboRpos(rpos) != SH::_NoError)
32879 {
32880 break;
32881 }
32882
32883 set_register(sarg1, do_trigger_combo(get_rpos_handle(rpos, lyr)) ? 10000 : 0);
32884 break;
32885 }
32886
32887 case SWITCHNPC:
32888 {
32889 byte effect = vbound(get_register(sarg1)/10000, 0, 255);
32890 set_register(sarg1,0);
32891 if(Hero.switchhookclk) break; //Already switching!
32892 if(GuyH::loadNPC(ri->guyref) == SH::_NoError)
32893 {
32894 switching_object = guys.getByUID(ri->guyref);
32895 hooked_comborpos = rpos_t::None;
32896 hooked_layerbits = 0;
32897 switching_object->switch_hooked = true;
32898 Hero.doSwitchHook(effect);
32899 set_register(sarg1,10000);
32900 }
32901 break;
32902 }
32903
32904 case SWITCHITM:
32905 {
32906 byte effect = vbound(get_register(sarg1)/10000, 0, 255);
32907 set_register(sarg1,0);
32908 if(Hero.switchhookclk) break; //Already switching!
32909 if(ItemH::loadItem(ri->itemref) == SH::_NoError)
32910 {
32911 switching_object = ItemH::getItem();
32912 hooked_comborpos = rpos_t::None;
32913 hooked_layerbits = 0;
32914 switching_object->switch_hooked = true;
32915 Hero.doSwitchHook(effect);
32916 set_register(sarg1,10000);
32917 }
32918 break;
32919 }
32920
32921 case SWITCHLW:
32922 {
32923 byte effect = vbound(get_register(sarg1)/10000, 0, 255);
32924 set_register(sarg1,0);
32925 if(Hero.switchhookclk) break; //Already switching!
32926 if(LwpnH::loadWeapon(ri->lwpn) == SH::_NoError)
32927 {
32928 switching_object = LwpnH::getWeapon();
32929 hooked_comborpos = rpos_t::None;
32930 hooked_layerbits = 0;
32931 switching_object->switch_hooked = true;
32932 Hero.doSwitchHook(effect);
32933 set_register(sarg1,10000);
32934 }
32935 break;
32936 }
32937
32938 case SWITCHEW:
32939 {
32940 byte effect = vbound(get_register(sarg1)/10000, 0, 255);
32941 set_register(sarg1,0);
32942 if(Hero.switchhookclk) break; //Already switching!
32943 if(EwpnH::loadWeapon(ri->ewpn) == SH::_NoError)
32944 {
32945 switching_object = EwpnH::getWeapon();
32946 hooked_comborpos = rpos_t::None;
32947 hooked_layerbits = 0;
32948 switching_object->switch_hooked = true;
32949 Hero.doSwitchHook(effect);
32950 set_register(sarg1,10000);
32951 }
32952 break;
32953 }
32954
32955 case SWITCHCMB:
32956 {
32957 rpos_t rpos = (rpos_t)(get_register(sarg1)/10000);
32958 set_register(sarg1,0);
32959 if(Hero.switchhookclk) break; //Already switching!
32960 if (!is_valid_rpos(rpos))
32961 break;
32962 switching_object = NULL;
32963 hooked_comborpos = rpos;
32964 hooked_layerbits = 0;
32965 Hero.doSwitchHook(get_register(sarg2)/10000);
32966 if(!hooked_layerbits) //failed
32967 Hero.reset_hookshot();
32968 else set_register(sarg1,10000); //success return
32969 break;
32970 }
32971
32972 case LINKWARPEXR:
32973 {
32974 92 FFCore.do_warp_ex(false);
32975 92 break;
32976 }
32977
32978 case KILLPLAYER:
32979 {
32980 Hero.kill(get_register(sarg1));
32981 break;
32982 }
32983
32984 case HEROMOVEXY:
32985 {
32986 1798 zfix dx = zslongToFix(SH::read_stack(ri->sp + 4));
32987 1798 zfix dy = zslongToFix(SH::read_stack(ri->sp + 3));
32988 1798 bool kb = SH::read_stack(ri->sp + 2)!=0;
32989 1798 bool ign_sv = SH::read_stack(ri->sp + 1)!=0;
32990 1798 bool shove = SH::read_stack(ri->sp + 0)!=0;
32991 1798 ri->d[rEXP1] = Hero.movexy(dx, dy, kb, ign_sv, shove) ? 10000 : 0;
32992 1798 break;
32993 }
32994 case HEROCANMOVEXY:
32995 {
32996 3596 zfix dx = zslongToFix(SH::read_stack(ri->sp + 4));
32997 3596 zfix dy = zslongToFix(SH::read_stack(ri->sp + 3));
32998 3596 bool kb = SH::read_stack(ri->sp + 2)!=0;
32999 3596 bool ign_sv = SH::read_stack(ri->sp + 1)!=0;
33000 3596 bool shove = SH::read_stack(ri->sp + 0)!=0;
33001 3596 ri->d[rEXP1] = Hero.can_movexy(dx, dy, kb, ign_sv, shove) ? 10000 : 0;
33002 3596 break;
33003 }
33004 case HEROMOVEATANGLE:
33005 {
33006 zfix degrees = zslongToFix(SH::read_stack(ri->sp + 4));
33007 zfix pxamnt = zslongToFix(SH::read_stack(ri->sp + 3));
33008 bool kb = SH::read_stack(ri->sp + 2)!=0;
33009 bool ign_sv = SH::read_stack(ri->sp + 1)!=0;
33010 bool shove = SH::read_stack(ri->sp + 0)!=0;
33011 ri->d[rEXP1] = Hero.moveAtAngle(degrees, pxamnt, kb, ign_sv, shove) ? 10000 : 0;
33012 break;
33013 }
33014 case HEROCANMOVEATANGLE:
33015 {
33016 zfix degrees = zslongToFix(SH::read_stack(ri->sp + 4));
33017 zfix pxamnt = zslongToFix(SH::read_stack(ri->sp + 3));
33018 bool kb = SH::read_stack(ri->sp + 2)!=0;
33019 bool ign_sv = SH::read_stack(ri->sp + 1)!=0;
33020 bool shove = SH::read_stack(ri->sp + 0)!=0;
33021 ri->d[rEXP1] = Hero.can_moveAtAngle(degrees, pxamnt, kb, ign_sv, shove) ? 10000 : 0;
33022 break;
33023 }
33024 case HEROMOVE:
33025 {
33026 int dir = SH::read_stack(ri->sp + 4)/10000;
33027 zfix pxamnt = zslongToFix(SH::read_stack(ri->sp + 3));
33028 bool kb = SH::read_stack(ri->sp + 2)!=0;
33029 bool ign_sv = SH::read_stack(ri->sp + 1)!=0;
33030 bool shove = SH::read_stack(ri->sp + 0)!=0;
33031 ri->d[rEXP1] = Hero.moveDir(dir, pxamnt, kb, ign_sv, shove) ? 10000 : 0;
33032 break;
33033 }
33034 case HEROCANMOVE:
33035 {
33036 440764 int dir = SH::read_stack(ri->sp + 4)/10000;
33037 440764 zfix pxamnt = zslongToFix(SH::read_stack(ri->sp + 3));
33038 440764 bool kb = SH::read_stack(ri->sp + 2)!=0;
33039 440764 bool ign_sv = SH::read_stack(ri->sp + 1)!=0;
33040 440764 bool shove = SH::read_stack(ri->sp + 0)!=0;
33041 440764 ri->d[rEXP1] = Hero.can_moveDir(dir, pxamnt, kb, ign_sv, shove) ? 10000 : 0;
33042 440764 break;
33043 }
33044 case HEROLIFTRELEASE:
33045 {
33046 if(Hero.lift_wpn)
33047 {
33048 ri->d[rEXP1] = Hero.lift_wpn->getUID();
33049 Lwpns.add(Hero.lift_wpn);
33050 Hero.lift_wpn = nullptr;
33051 }
33052 else ri->d[rEXP1] = 0;
33053 break;
33054 }
33055 case HEROLIFTGRAB:
33056 {
33057 auto lwuid = SH::read_stack(ri->sp + 2);
33058 auto lifttime = SH::read_stack(ri->sp + 1)/10000;
33059 auto liftheight = zslongToFix(SH::read_stack(ri->sp + 0));
33060 if(weapon* wpn = checkLWpn(lwuid))
33061 {
33062 Hero.lift(wpn, lifttime, liftheight);
33063 if(Lwpns.find(wpn) > -1)
33064 Lwpns.remove(wpn);
33065 if(type == ScriptType::Lwpn && lwuid == i)
33066 earlyretval = RUNSCRIPT_SELFREMOVE;
33067 }
33068 break;
33069 }
33070 case HEROISFLICKERFRAME:
33071 ri->d[rEXP1] = Hero.is_hitflickerframe() ? 10000 : 0;
33072 break;
33073 case LOADPORTAL:
33074 {
33075 auto val = get_register(sarg1)/10000;
33076 if(val != -1)
33077 {
33078 portal* prt = (portal*)portals.spr(val);
33079 if(prt)
33080 val = prt->getUID();
33081 else
33082 {
33083 Z_scripterrlog("Tried to load invalid portal index '%d'\n", val);
33084 val = 0;
33085 }
33086 }
33087 ri->portalref = ri->d[rEXP1] = val;
33088 break;
33089 }
33090 case CREATEPORTAL:
33091 {
33092 portal* p = new portal();
33093 if(portals.add(p))
33094 ri->portalref = ri->d[rEXP1] = p->getUID();
33095 else
33096 {
33097 ri->portalref = ri->d[rEXP1] = 0;
33098 Z_scripterrlog("Unable to create new portal! Limit reached!\n");
33099 }
33100 break;
33101 }
33102 case LOADSAVPORTAL:
33103 {
33104 auto val = get_register(sarg1)/10000;
33105 savedportal* prt = checkSavedPortal(val);
33106 ri->saveportalref = ri->d[rEXP1] = prt ? val : 0;
33107 break;
33108 }
33109 case CREATESAVPORTAL:
33110 {
33111 if(game->user_portals.size() >= MAX_SAVED_PORTALS)
33112 {
33113 ri->saveportalref = ri->d[rEXP1] = 0;
33114 Z_scripterrlog("Cannot create any more Saved Portals! Remove some first!\n");
33115 break;
33116 }
33117 savedportal& ref = game->user_portals.emplace_back();
33118 ri->saveportalref = ri->d[rEXP1] = ref.getUID();
33119 break;
33120 }
33121 case PORTALREMOVE:
33122 {
33123 if(portal* p = checkPortal(ri->portalref, true))
33124 {
33125 if(p == &mirror_portal)
33126 p->clear();
33127 else
33128 {
33129 auto id = portals.find(p);
33130 if(id > -1)
33131 portals.del(id,true);
33132 }
33133 }
33134 break;
33135 }
33136 case PORTALUSESPRITE:
33137 do_portalusesprite();
33138 break;
33139 case SAVEDPORTALREMOVE:
33140 {
33141 if(savedportal* sp = checkSavedPortal(ri->saveportalref, true))
33142 {
33143 if(sp == &(game->saved_mirror_portal))
33144 sp->clear();
33145 else
33146 {
33147 //ensure all pointers to the object are cleared before deleting
33148 portals.forEach([&](sprite& spr)
33149 {
33150 portal* tmp = (portal*)&spr;
33151 if(sp->getUID() == tmp->saved_data)
33152 {
33153 tmp->saved_data = 0;
33154 }
33155 return false;
33156 });
33157 //delete the savedportal object from the vector
33158 for(auto it = game->user_portals.begin();
33159 it != game->user_portals.end();)
33160 {
33161 savedportal& tmp = *it;
33162 if(sp == &tmp)
33163 {
33164 game->user_portals.erase(it);
33165 break;
33166 }
33167 else ++it;
33168 }
33169 }
33170 }
33171 break;
33172 }
33173 case SAVEDPORTALGENERATE:
33174 {
33175 auto retval = 0;
33176 if(savedportal* sp = checkSavedPortal(ri->saveportalref))
33177 {
33178 retval = getPortalFromSaved(sp);
33179 if(!retval)
33180 {
33181 if(portal* p = loadportal(*sp))
33182 if(portals.add(p))
33183 retval = p->getUID();
33184 }
33185 }
33186 ri->d[rEXP1] = retval;
33187 break;
33188 }
33189
33190 case LINKEXPLODER:
33191 {
33192 int32_t mode = get_register(sarg1) / 10000;
33193 if ( (unsigned) mode > 2 )
33194 {
33195 Z_scripterrlog("Invalid mode (%d) passed to Hero->Explode(int32_t mode)\n",mode);
33196 }
33197 else Hero.explode(mode);
33198 break;
33199 }
33200 case NPCEXPLODER:
33201 {
33202 int32_t mode = get_register(sarg1) / 10000;
33203 if ( (unsigned) mode > 2 )
33204 {
33205 Z_scripterrlog("Invalid mode (%d) passed to npc->Explode(int32_t mode)\n",mode);
33206 }
33207 else
33208 {
33209 if(GuyH::loadNPC(ri->guyref) == SH::_NoError)
33210 {
33211 GuyH::getNPC()->explode(mode);
33212 }
33213 }
33214 break;
33215 }
33216
33217 case ITEMEXPLODER:
33218 {
33219
33220 int32_t mode = get_register(sarg1) / 10000;
33221 if ( (unsigned) mode > 2 )
33222 {
33223 Z_scripterrlog("Invalid mode (%d) passed to item->Explode(int32_t mode)\n",mode);
33224 }
33225 else
33226 {
33227 if(ItemH::loadItem(ri->itemref) == SH::_NoError)
33228 {
33229 ItemH::getItem()->explode(mode);
33230 }
33231 }
33232 break;
33233 }
33234 case LWEAPONEXPLODER:
33235 {
33236 int32_t mode = get_register(sarg1) / 10000;
33237 if ( (unsigned) mode > 2 )
33238 {
33239 Z_scripterrlog("Invalid mode (%d) passed to lweapon->Explode(int32_t mode)\n",mode);
33240 }
33241 else
33242 {
33243 if(LwpnH::loadWeapon(ri->lwpn) == SH::_NoError)
33244 {
33245 LwpnH::getWeapon()->explode(mode);
33246 }
33247 }
33248 break;
33249 }
33250 case EWEAPONEXPLODER:
33251 {
33252 int32_t mode = get_register(sarg1) / 10000;
33253 if ( (unsigned) mode > 2 )
33254 {
33255 Z_scripterrlog("Invalid mode (%d) passed to eweapon->Explode(int32_t mode)\n",mode);
33256 }
33257 else
33258 {
33259 if(EwpnH::loadWeapon(ri->ewpn) == SH::_NoError)
33260 {
33261 EwpnH::getWeapon()->explode(mode);
33262 }
33263 }
33264 break;
33265 }
33266
33267 case BOTTLENAMEGET:
33268 {
33269 int32_t arrayptr = get_register(sarg1) / 10000;
33270 int32_t id = ri->bottletyperef-1;
33271 if(unsigned(id) > 63)
33272 {
33273 Z_scripterrlog("Invalid bottledata ID (%d) passed to bottledata->GetName().\n", id);
33274 break;
33275 }
33276
33277 if(ArrayH::setArray(arrayptr, QMisc.bottle_types[id].name) == SH::_Overflow)
33278 Z_scripterrlog("Array supplied to 'bottledata->GetName()' not large enough\n");
33279 break;
33280 }
33281 case BOTTLENAMESET:
33282 {
33283 int32_t arrayptr = get_register(sarg1) / 10000;
33284 int32_t id = ri->bottletyperef-1;
33285 if(unsigned(id) > 63)
33286 {
33287 Z_scripterrlog("Invalid bottledata ID (%d) passed to bottledata->SetName().\n", id+1);
33288 break;
33289 }
33290 string name;
33291 ArrayH::getString(arrayptr, name, 31);
33292 strcpy(QMisc.bottle_types[id].name, name.c_str());
33293 break;
33294 }
33295 case BSHOPNAMEGET:
33296 {
33297 int32_t arrayptr = get_register(sarg1) / 10000;
33298 int32_t id = ri->bottleshopref-1;
33299 if(unsigned(id) > 255)
33300 {
33301 Z_scripterrlog("Invalid bottleshopdata ID (%d) passed to bottleshopdata->GetName().\n", id+1);
33302 break;
33303 }
33304
33305 if(ArrayH::setArray(arrayptr, QMisc.bottle_shop_types[id].name) == SH::_Overflow)
33306 Z_scripterrlog("Array supplied to 'bottleshopdata->GetName()' not large enough\n");
33307 break;
33308 }
33309 case BSHOPNAMESET:
33310 {
33311 int32_t arrayptr = get_register(sarg1) / 10000;
33312 int32_t id = ri->bottleshopref;
33313 if(unsigned(id) > 255)
33314 {
33315 Z_scripterrlog("Invalid bottleshopdata ID (%d) passed to bottleshopdata->SetName().\n", id);
33316 break;
33317 }
33318 string name;
33319 ArrayH::getString(arrayptr, name, 31);
33320 strcpy(QMisc.bottle_shop_types[id].name, name.c_str());
33321 break;
33322 }
33323
33324 case RUNITEMSCRIPT:
33325 {
33326 15 int32_t itemid = ri->idata;
33327
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if(unsigned(itemid) > MAXITEMS) break;
33328 15 int32_t mode = get_register(sarg1) / 10000;
33329 15 auto& data = get_script_engine_data(ScriptType::Item, itemid);
33330
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15 times.
15 switch(mode)
33331 {
33332 case 0:
33333 {
33334 data.doscript = 4;
33335 break;
33336 }
33337 case 1:
33338 {
33339 if ( itemsbuf[itemid].script != 0 ) //&& !data.doscript )
33340 {
33341 if ( !data.doscript )
33342 {
33343 data.ref.Clear();
33344 data.doscript = 1;
33345 //ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[itemid].script, itemid);
33346 }
33347 else
33348 {
33349 //Emily, clear the stack here, clear refinfo, and set up to run again on the next frame from the beginning.
33350 }
33351 }
33352 break;
33353 }
33354 15 case 2:
33355 default:
33356 {
33357
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if ( itemsbuf[itemid].script != 0 ) //&& !data.doscript )
33358 {
33359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if (data.doscript != 2 )data.doscript = 2;
33360 15 }
33361 15 break;
33362 }
33363 /*
33364 case 0:
33365 {
33366 data.doscript = 0;
33367 break;
33368 }
33369 default:
33370 {
33371
33372 if ( itemsbuf[itemid].script != 0 ) //&& !data.doscript )
33373 {
33374 //itemScriptData[itemid].Clear();
33375 //for ( int32_t q = 0; q < 1024; q++ ) item_stack[itemid][q] = 0;
33376 //ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[itemid].script, itemid & 0xFFF);
33377 data.doscript = 2;
33378 }
33379 break;
33380 }
33381 */
33382 }
33383 15 break;
33384 }
33385
33386 //case NPCData
33387
33388 case GETNPCDATATILE: FFScript::getNPCData_tile(); break;
33389 case GETNPCDATAEHEIGHT: FFScript::getNPCData_e_height(); break;
33390 case GETNPCDATAFLAGS: FFScript::getNPCData_flags(); break;
33391 case GETNPCDATAFLAGS2: FFScript::getNPCData_flags2(); break;
33392 case GETNPCDATAWIDTH: FFScript::getNPCData_width(); break;
33393 case GETNPCDATAHEIGHT: FFScript::getNPCData_height(); break;
33394 case GETNPCDATASTILE: FFScript::getNPCData_s_tile(); break;
33395 case GETNPCDATASWIDTH: FFScript::getNPCData_s_width(); break;
33396 case GETNPCDATASHEIGHT: FFScript::getNPCData_s_height(); break;
33397 case GETNPCDATAETILE: FFScript::getNPCData_e_tile(); break;
33398 case GETNPCDATAEWIDTH: FFScript::getNPCData_e_width(); break;
33399 case GETNPCDATAHP: FFScript::getNPCData_hp(); break;
33400 case GETNPCDATAFAMILY: FFScript::getNPCData_family(); break;
33401 case GETNPCDATACSET: FFScript::getNPCData_cset(); break;
33402 case GETNPCDATAANIM: FFScript::getNPCData_anim(); break;
33403 case GETNPCDATAEANIM: FFScript::getNPCData_e_anim(); break;
33404 case GETNPCDATAFRAMERATE: FFScript::getNPCData_frate(); break;
33405 case GETNPCDATAEFRAMERATE: FFScript::getNPCData_e_frate(); break;
33406 case GETNPCDATATOUCHDMG: FFScript::getNPCData_dp(); break;
33407 case GETNPCDATAWPNDAMAGE: FFScript::getNPCData_wdp(); break;
33408 case GETNPCDATAWEAPON: FFScript::getNPCData_wdp(); break;
33409 case GETNPCDATARANDOM: FFScript::getNPCData_rate(); break;
33410 case GETNPCDATAHALT: FFScript::getNPCData_hrate(); break;
33411 case GETNPCDATASTEP: FFScript::getNPCData_step(); break;
33412 case GETNPCDATAHOMING: FFScript::getNPCData_homing(); break;
33413 case GETNPCDATAHUNGER: FFScript::getNPCData_grumble(); break;
33414 case GETNPCDATADROPSET: FFScript::getNPCData_item_set(); break;
33415 case GETNPCDATABGSFX: FFScript::getNPCData_bgsfx(); break;
33416 case GETNPCDATADEATHSFX: FFScript::getNPCData_deadsfx(); break;
33417 case GETNPCDATAXOFS: FFScript::getNPCData_xofs(); break;
33418 case GETNPCDATAYOFS: FFScript::getNPCData_yofs(); break;
33419 case GETNPCDATAZOFS: FFScript::getNPCData_zofs(); break;
33420 case GETNPCDATAHXOFS: FFScript::getNPCData_hxofs(); break;
33421 case GETNPCDATAHYOFS: FFScript::getNPCData_hyofs(); break;
33422 case GETNPCDATAHITWIDTH: FFScript::getNPCData_hxsz(); break;
33423 case GETNPCDATAHITHEIGHT: FFScript::getNPCData_hysz(); break;
33424 case GETNPCDATAHITZ: FFScript::getNPCData_hzsz(); break;
33425 case GETNPCDATATILEWIDTH: FFScript::getNPCData_txsz(); break;
33426 case GETNPCDATATILEHEIGHT: FFScript::getNPCData_tysz(); break;
33427 case GETNPCDATAWPNSPRITE: FFScript::getNPCData_wpnsprite(); break;
33428 //case GETNPCDATASCRIPTDEF: FFScript::getNPCData_scriptdefence(); break; //2.future cross-compat.
33429 case GETNPCDATADEFENSE: FFScript::getNPCData_defense(); break;
33430 case GETNPCDATASIZEFLAG: FFScript::getNPCData_SIZEflags(); break;
33431 case GETNPCDATAATTRIBUTE: FFScript::getNPCData_misc(); break;
33432 case GETNPCDATAHITSFX: FFScript::getNPCData_hitsfx(); break;
33433
33434 case SETNPCDATAFLAGS: FFScript::setNPCData_flags(); break;
33435 case SETNPCDATAFLAGS2: FFScript::setNPCData_flags2(); break;
33436 case SETNPCDATAWIDTH: FFScript::setNPCData_width(); break;
33437 case SETNPCDATAHEIGHT: FFScript::setNPCData_height(); break;
33438 case SETNPCDATASTILE: FFScript::setNPCData_s_tile(); break;
33439 case SETNPCDATASWIDTH: FFScript::setNPCData_s_width(); break;
33440 case SETNPCDATASHEIGHT: FFScript::setNPCData_s_height(); break;
33441 case SETNPCDATAETILE: FFScript::setNPCData_e_tile(); break;
33442 case SETNPCDATAEWIDTH: FFScript::setNPCData_e_width(); break;
33443 case SETNPCDATAHP: FFScript::setNPCData_hp(); break;
33444 case SETNPCDATAFAMILY: FFScript::setNPCData_family(); break;
33445 case SETNPCDATACSET: FFScript::setNPCData_cset(); break;
33446 case SETNPCDATAANIM: FFScript::setNPCData_anim(); break;
33447 case SETNPCDATAEANIM: FFScript::setNPCData_e_anim(); break;
33448 case SETNPCDATAFRAMERATE: FFScript::setNPCData_frate(); break;
33449 case SETNPCDATAEFRAMERATE: FFScript::setNPCData_e_frate(); break;
33450 case SETNPCDATATOUCHDMG: FFScript::setNPCData_dp(); break;
33451 case SETNPCDATAWPNDAMAGE: FFScript::setNPCData_wdp(); break;
33452 case SETNPCDATAWEAPON: FFScript::setNPCData_weapon(); break;
33453 case SETNPCDATARANDOM: FFScript::setNPCData_rate(); break;
33454 case SETNPCDATAHALT: FFScript::setNPCData_hrate(); break;
33455 case SETNPCDATASTEP: FFScript::setNPCData_step(); break;
33456 case SETNPCDATAHOMING: FFScript::setNPCData_homing(); break;
33457 case SETNPCDATAHUNGER: FFScript::setNPCData_grumble(); break;
33458 case SETNPCDATADROPSET: FFScript::setNPCData_item_set(); break;
33459 case SETNPCDATABGSFX: FFScript::setNPCData_bgsfx(); break;
33460 case SETNPCDATADEATHSFX: FFScript::setNPCData_hitsfx(); break;
33461 case SETNPCDATAXOFS: FFScript::setNPCData_xofs(); break;
33462 case SETNPCDATAYOFS: FFScript::setNPCData_yofs(); break;
33463 case SETNPCDATAZOFS: FFScript::setNPCData_zofs(); break;
33464 case SETNPCDATAHXOFS: FFScript::setNPCData_hxofs(); break;
33465 case SETNPCDATAHYOFS: FFScript::setNPCData_hyofs(); break;
33466 case SETNPCDATAHITWIDTH: FFScript::setNPCData_hxsz(); break;
33467 case SETNPCDATAHITHEIGHT: FFScript::setNPCData_hysz(); break;
33468 case SETNPCDATAHITZ: FFScript::setNPCData_hzsz(); break;
33469 case SETNPCDATATILEWIDTH: FFScript::setNPCData_txsz(); break;
33470 case SETNPCDATATILEHEIGHT: FFScript::setNPCData_tysz(); break;
33471 case SETNPCDATAWPNSPRITE: FFScript::setNPCData_wpnsprite(); break;
33472 case SETNPCDATAHITSFX: FFScript::setNPCData_hitsfx(); break;
33473 case SETNPCDATATILE: FFScript::setNPCData_tile(); break;
33474 case SETNPCDATAEHEIGHT: FFScript::setNPCData_e_height(); break;
33475
33476
33477
33478
33479
33480
33481 //case SETNPCDATASCRIPTDEF : FFScript::setNPCData_scriptdefence(); break;
33482 case SETNPCDATADEFENSE : FFScript::setNPCData_defense(ri->d[rEXP1]); break;
33483 case SETNPCDATASIZEFLAG : FFScript::setNPCData_SIZEflags(ri->d[rEXP1]); break;
33484 case SETNPCDATAATTRIBUTE : FFScript::setNPCData_misc(ri->d[rEXP1]); break;
33485
33486
33487 //ComboData
33488
33489 case GCDBLOCKENEM: FFScript::getComboData_block_enemies(); break;
33490 case GCDBLOCKHOLE: FFScript::getComboData_block_hole(); break;
33491 case GCDBLOCKTRIG: FFScript::getComboData_block_trigger(); break;
33492 case GCDCONVEYSPDX: FFScript::getComboData_conveyor_x_speed(); break;
33493 case GCDCONVEYSPDY: FFScript::getComboData_conveyor_y_speed(); break;
33494 case GCDCREATEENEM: FFScript::getComboData_create_enemy(); break;
33495 case GCDCREATEENEMWH: FFScript::getComboData_create_enemy_when(); break;
33496 case GCDCREATEENEMCH: FFScript::getComboData_create_enemy_change(); break;
33497 case GCDDIRCHTYPE: FFScript::getComboData_directional_change_type(); break;
33498 case GCDDISTCHTILES: FFScript::getComboData_distance_change_tiles(); break;
33499 case GCDDIVEITEM: FFScript::getComboData_dive_item(); break;
33500 case GCDDOCK: FFScript::getComboData_dock(); break;
33501 case GCDFAIRY: FFScript::getComboData_fairy(); break;
33502 case GCDFFCOMBOATTRIB: FFScript::getComboData_ff_combo_attr_change(); break;
33503 case GCDFOOTDECOTILE: FFScript::getComboData_foot_decorations_tile(); break;
33504 case GCDFOOTDECOTYPE: FFScript::getComboData_foot_decorations_type(); break;
33505 case GCDHOOKSHOTGRAB: FFScript::getComboData_hookshot_grab_point(); break;
33506 case GCDLADDERPASS: FFScript::getComboData_ladder_pass(); break;
33507 case GCDLOCKBLOCKTYPE: FFScript::getComboData_lock_block_type(); break;
33508 case GCDLOCKBLOCKCHANGE: FFScript::getComboData_lock_block_change(); break;
33509 case GCDMAGICMIRRORTYPE: FFScript::getComboData_magic_mirror_type(); break;
33510 case GCDMODIFYHPAMOUNT: FFScript::getComboData_modify_hp_amount(); break;
33511 case GCDMODIFYHPDELAY: FFScript::getComboData_modify_hp_delay(); break;
33512 case GCDMODIFYHPTYPE: FFScript::getComboData_modify_hp_type(); break;
33513 case GCDMODIFYMPAMOUNT: FFScript::getComboData_modify_mp_amount(); break;
33514 case GCDMODIFYMPDELAY: FFScript::getComboData_modify_mp_delay(); break;
33515 case GCDMODIFYMPTYPE: FFScript::getComboData_modify_mp_type(); break;
33516 case GCDNOPUSHBLOCKS: FFScript::getComboData_no_push_blocks(); break;
33517 case GCDOVERHEAD: FFScript::getComboData_overhead(); break;
33518 case GCDPLACEENEMY: FFScript::getComboData_place_enemy(); break;
33519 case GCDPUSHDIR: FFScript::getComboData_push_direction(); break;
33520 case GCDPUSHWEIGHT: FFScript::getComboData_push_weight(); break;
33521 case GCDPUSHWAIT: FFScript::getComboData_push_wait(); break;
33522 case GCDPUSHED: FFScript::getComboData_pushed(); break;
33523 case GCDRAFT: FFScript::getComboData_raft(); break;
33524 case GCDRESETROOM: FFScript::getComboData_reset_room(); break;
33525 case GCDSAVEPOINT: FFScript::getComboData_save_point_type(); break;
33526 case GCDSCREENFREEZE: FFScript::getComboData_screen_freeze_type(); break;
33527 case GCDSECRETCOMBO: FFScript::getComboData_secret_combo(); break;
33528 case GCDSINGULAR: FFScript::getComboData_singular(); break;
33529 case GCDSLOWMOVE: FFScript::getComboData_slow_movement(); break;
33530 case GCDSTATUE: FFScript::getComboData_statue_type(); break;
33531 case GCDSTEPTYPE: FFScript::getComboData_step_type(); break;
33532 case GCDSTEPCHANGETO: FFScript::getComboData_step_change_to(); break;
33533 case GCDSTRIKEREMNANTS: FFScript::getComboData_strike_remnants(); break;
33534 case GCDSTRIKEREMNANTSTYPE: FFScript::getComboData_strike_remnants_type(); break;
33535 case GCDSTRIKECHANGE: FFScript::getComboData_strike_change(); break;
33536 case GCDSTRIKECHANGEITEM: FFScript::getComboData_strike_item(); break;
33537 case GCDTOUCHITEM: FFScript::getComboData_touch_item(); break;
33538 case GCDTOUCHSTAIRS: FFScript::getComboData_touch_stairs(); break;
33539 case GCDTRIGGERTYPE: FFScript::getComboData_trigger_type(); break;
33540 case GCDTRIGGERSENS: FFScript::getComboData_trigger_sensitive(); break;
33541 case GCDWARPTYPE: FFScript::getComboData_warp_type(); break;
33542 case GCDWARPSENS: FFScript::getComboData_warp_sensitive(); break;
33543 case GCDWARPDIRECT: FFScript::getComboData_warp_direct(); break;
33544 case GCDWARPLOCATION: FFScript::getComboData_warp_location(); break;
33545 case GCDWATER: FFScript::getComboData_water(); break;
33546 case GCDWHISTLE: FFScript::getComboData_whistle(); break;
33547 case GCDWINGAME: FFScript::getComboData_win_game(); break;
33548 case GCDBLOCKWEAPLVL: FFScript::getComboData_block_weapon_lvl(); break;
33549 case GCDTILE: FFScript::getComboData_tile(); break;
33550 case GCDFLIP: FFScript::getComboData_flip(); break;
33551 case GCDWALK: FFScript::getComboData_walk(); break;
33552 case GCDTYPE: FFScript::getComboData_type(); break;
33553 case GCDCSETS: FFScript::getComboData_csets(); break;
33554 case GCDFOO: break;
33555 case GCDFRAMES: FFScript::getComboData_frames(); break;
33556 case GCDSPEED: FFScript::getComboData_speed(); break;
33557 case GCDNEXTCOMBO: FFScript::getComboData_nextcombo(); break;
33558 case GCDNEXTCSET: FFScript::getComboData_nextcset(); break;
33559 case GCDFLAG: FFScript::getComboData_flag(); break;
33560 case GCDSKIPANIM: FFScript::getComboData_skipanim(); break;
33561 case GCDNEXTTIMER: FFScript::getComboData_nexttimer(); break;
33562 case GCDSKIPANIMY: FFScript::getComboData_skipanimy(); break;
33563 case GCDANIMFLAGS: FFScript::getComboData_animflags(); break;
33564 case GCDBLOCKWEAPON: FFScript::getComboData_block_weapon(); break;
33565 case GCDEXPANSION: FFScript::getComboData_expansion(); break;
33566 case GCDSTRIKEWEAPONS: FFScript::getComboData_strike_weapons(); break;
33567 case SCDBLOCKENEM: FFScript::setComboData_block_enemies(); break;
33568 case SCDBLOCKHOLE: FFScript::setComboData_block_hole(); break;
33569 case SCDBLOCKTRIG: FFScript::setComboData_block_trigger(); break;
33570 case SCDCONVEYSPDX: FFScript::setComboData_conveyor_x_speed(); break;
33571 case SCDCONVEYSPDY: FFScript::setComboData_conveyor_y_speed(); break;
33572 case SCDCREATEENEM: FFScript::setComboData_create_enemy(); break;
33573 case SCDCREATEENEMWH: FFScript::setComboData_create_enemy_when(); break;
33574 case SCDCREATEENEMCH: FFScript::setComboData_create_enemy_change(); break;
33575 case SCDDIRCHTYPE: FFScript::setComboData_directional_change_type(); break;
33576 case SCDDISTCHTILES: FFScript::setComboData_distance_change_tiles(); break;
33577 case SCDDIVEITEM: FFScript::setComboData_dive_item(); break;
33578 case SCDDOCK: FFScript::setComboData_dock(); break;
33579 case SCDFAIRY: FFScript::setComboData_fairy(); break;
33580 case SCDFFCOMBOATTRIB: FFScript::setComboData_ff_combo_attr_change(); break;
33581 case SCDFOOTDECOTILE: FFScript::setComboData_foot_decorations_tile(); break;
33582 case SCDFOOTDECOTYPE: FFScript::setComboData_foot_decorations_type(); break;
33583 case SCDHOOKSHOTGRAB: FFScript::setComboData_hookshot_grab_point(); break;
33584 case SCDLADDERPASS: FFScript::setComboData_ladder_pass(); break;
33585 case SCDLOCKBLOCKTYPE: FFScript::setComboData_lock_block_type(); break;
33586 case SCDLOCKBLOCKCHANGE: FFScript::setComboData_lock_block_change(); break;
33587 case SCDMAGICMIRRORTYPE: FFScript::setComboData_magic_mirror_type(); break;
33588 case SCDMODIFYHPAMOUNT: FFScript::setComboData_modify_hp_amount(); break;
33589 case SCDMODIFYHPDELAY: FFScript::setComboData_modify_hp_delay(); break;
33590 case SCDMODIFYHPTYPE: FFScript::setComboData_modify_hp_type(); break;
33591 case SCDMODIFYMPAMOUNT: FFScript::setComboData_modify_mp_amount(); break;
33592 case SCDMODIFYMPDELAY: FFScript::setComboData_modify_mp_delay(); break;
33593 case SCDMODIFYMPTYPE: FFScript::setComboData_modify_mp_type(); break;
33594 case SCDNOPUSHBLOCKS: FFScript::setComboData_no_push_blocks(); break;
33595 case SCDOVERHEAD: FFScript::setComboData_overhead(); break;
33596 case SCDPLACEENEMY: FFScript::setComboData_place_enemy(); break;
33597 case SCDPUSHDIR: FFScript::setComboData_push_direction(); break;
33598 case SCDPUSHWEIGHT: FFScript::setComboData_push_weight(); break;
33599 case SCDPUSHWAIT: FFScript::setComboData_push_wait(); break;
33600 case SCDPUSHED: FFScript::setComboData_pushed(); break;
33601 case SCDRAFT: FFScript::setComboData_raft(); break;
33602 case SCDRESETROOM: FFScript::setComboData_reset_room(); break;
33603 case SCDSAVEPOINT: FFScript::setComboData_save_point_type(); break;
33604 case SCDSCREENFREEZE: FFScript::setComboData_screen_freeze_type(); break;
33605 case SCDSECRETCOMBO: FFScript::setComboData_secret_combo(); break;
33606 case SCDSINGULAR: FFScript::setComboData_singular(); break;
33607 case SCDSLOWMOVE: FFScript::setComboData_slow_movement(); break;
33608 case SCDSTATUE: FFScript::setComboData_statue_type(); break;
33609 case SCDSTEPTYPE: FFScript::setComboData_step_type(); break;
33610 case SCDSTEPCHANGETO: FFScript::setComboData_step_change_to(); break;
33611 case SCDSTRIKEREMNANTS: FFScript::setComboData_strike_remnants(); break;
33612 case SCDSTRIKEREMNANTSTYPE: FFScript::setComboData_strike_remnants_type(); break;
33613 case SCDSTRIKECHANGE: FFScript::setComboData_strike_change(); break;
33614 case SCDSTRIKECHANGEITEM: FFScript::setComboData_strike_item(); break;
33615 case SCDTOUCHITEM: FFScript::setComboData_touch_item(); break;
33616 case SCDTOUCHSTAIRS: FFScript::setComboData_touch_stairs(); break;
33617 case SCDTRIGGERTYPE: FFScript::setComboData_trigger_type(); break;
33618 case SCDTRIGGERSENS: FFScript::setComboData_trigger_sensitive(); break;
33619 case SCDWARPTYPE: FFScript::setComboData_warp_type(); break;
33620 case SCDWARPSENS: FFScript::setComboData_warp_sensitive(); break;
33621 case SCDWARPDIRECT: FFScript::setComboData_warp_direct(); break;
33622 case SCDWARPLOCATION: FFScript::setComboData_warp_location(); break;
33623 case SCDWATER: FFScript::setComboData_water(); break;
33624 case SCDWHISTLE: FFScript::setComboData_whistle(); break;
33625 case SCDWINGAME: FFScript::setComboData_win_game(); break;
33626 case SCDBLOCKWEAPLVL: FFScript::setComboData_block_weapon_lvl(); break;
33627 case SCDTILE: FFScript::setComboData_tile(); break;
33628 case SCDFLIP: FFScript::setComboData_flip(); break;
33629 case SCDWALK: FFScript::setComboData_walk(); break;
33630 case SCDTYPE: FFScript::setComboData_type(); break;
33631 case SCDCSETS: FFScript::setComboData_csets(); break;
33632 case SCDFOO: break;
33633 case SCDFRAMES: FFScript::setComboData_frames(); break;
33634 case SCDSPEED: FFScript::setComboData_speed(); break;
33635 case SCDNEXTCOMBO: FFScript::setComboData_nextcombo(); break;
33636 case SCDNEXTCSET: FFScript::setComboData_nextcset(); break;
33637 case SCDFLAG: FFScript::setComboData_flag(); break;
33638 case SCDSKIPANIM: FFScript::setComboData_skipanim(); break;
33639 case SCDNEXTTIMER: FFScript::setComboData_nexttimer(); break;
33640 case SCDSKIPANIMY: FFScript::setComboData_skipanimy(); break;
33641 case SCDANIMFLAGS: FFScript::setComboData_animflags(); break;
33642 case SCDBLOCKWEAPON: FFScript::setComboData_block_weapon(ri->d[rEXP1]); break;
33643 case SCDEXPANSION: FFScript::setComboData_expansion(ri->d[rEXP1]); break;
33644 case SCDSTRIKEWEAPONS: FFScript::setComboData_strike_weapons(ri->d[rEXP1]); break;
33645
33646 //SpriteData
33647
33648 //case GETSPRITEDATASTRING:
33649 case GETSPRITEDATATILE: FFScript::getSpriteDataTile(); break;
33650 case GETSPRITEDATAMISC: FFScript::getSpriteDataCSets(); break;
33651 case GETSPRITEDATACGETS: FFScript::getSpriteDataCSets(); break;
33652 case GETSPRITEDATAFRAMES: FFScript::getSpriteDataFrames(); break;
33653 case GETSPRITEDATASPEED: FFScript::getSpriteDataSpeed(); break;
33654 case GETSPRITEDATATYPE: FFScript::getSpriteDataType(); break;
33655
33656 //case SETSPRITEDATASTRING:
33657 case SETSPRITEDATATILE: FFScript::setSpriteDataTile(); break;
33658 case SETSPRITEDATAMISC: FFScript::setSpriteDataMisc(); break;
33659 case SETSPRITEDATACSETS: FFScript::setSpriteDataCSets(); break;
33660 case SETSPRITEDATAFRAMES: FFScript::setSpriteDataFrames(); break;
33661 case SETSPRITEDATASPEED: FFScript::setSpriteDataSpeed(); break;
33662 case SETSPRITEDATATYPE: FFScript::setSpriteDataType(); break;
33663
33664 //Game over Screen
33665 case SETCONTINUESCREEN: FFScript::FFChangeSubscreenText(); break;
33666 case SETCONTINUESTRING: FFScript::FFSetSaveScreenSetting(); break;
33667
33668 case LWPNDEL:
33669 {
33670 8 FFScript::deallocateAllScriptOwned(ScriptType::Lwpn, ri->lwpn);
33671
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 if(type == ScriptType::Lwpn && ri->lwpn == i)
33672 {
33673 8 FFCore.do_lweapon_delete();
33674 8 return RUNSCRIPT_SELFDELETE;
33675 }
33676 FFCore.do_lweapon_delete();
33677 break;
33678 }
33679 case EWPNDEL:
33680 {
33681 46 FFScript::deallocateAllScriptOwned(ScriptType::Ewpn, ri->ewpn);
33682
3/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
46 if(type == ScriptType::Ewpn && ri->ewpn == i)
33683 {
33684 10 FFCore.do_eweapon_delete();
33685 10 return RUNSCRIPT_SELFDELETE;
33686 }
33687 36 FFCore.do_eweapon_delete();
33688 36 break;
33689 }
33690
33691 case PLAYENHMUSICEX:
33692 // DEPRECATED
33693 do_enh_music(false);
33694 break;
33695
33696 case GETENHMUSICPOS:
33697 FFCore.do_get_music_position();
33698 break;
33699
33700 case SETENHMUSICPOS:
33701 FFCore.do_set_music_position(false);
33702 break;
33703
33704 case SETENHMUSICSPEED:
33705 FFCore.do_set_music_speed(false);
33706 break;
33707
33708 case GETENHMUSICLEN:
33709 FFCore.do_get_music_length();
33710 break;
33711
33712 case SETENHMUSICLOOP:
33713 3 FFCore.do_set_music_loop();
33714 3 break;
33715
33716 case ENHCROSSFADE:
33717 5 do_enh_music_crossfade();
33718 5 break;
33719
33720 case DIREXISTS:
33721 FFCore.do_checkdir(true);
33722 break;
33723
33724 case FILEEXISTS:
33725 FFCore.do_checkdir(false);
33726 break;
33727
33728 case FILESYSREMOVE:
33729 FFCore.do_fs_remove();
33730 break;
33731
33732 case TOBYTE:
33733 do_tobyte();
33734 break;
33735 case TOWORD:
33736 do_toword();
33737 break;
33738 case TOSHORT: do_toshort(); break;
33739 case TOSIGNEDBYTE: do_tosignedbyte(); break;
33740 case TOINTEGER: do_tointeger(); break;
33741 case CEILING: do_ceiling(); break;
33742 7 case FLOOR: do_floor(); break;
33743 case TRUNCATE: do_trunc(); break;
33744 case ROUND: do_round(); break;
33745 case ROUNDAWAY: do_roundaway(); break;
33746
33747 case FILECLOSE:
33748 {
33749 FFCore.do_fclose();
33750 break;
33751 }
33752 case FILEFREE:
33753 {
33754 1 FFCore.do_deallocate_file();
33755 1 break;
33756 }
33757 case FILEOWN:
33758 {
33759 1 user_file* f = checkFile(ri->fileref, false);
33760
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(f) own_script_object(f, type, i);
33761 1 break;
33762 }
33763 case FILEISALLOCATED:
33764 {
33765 FFCore.do_file_isallocated();
33766 break;
33767 }
33768 case FILEISVALID:
33769 {
33770 FFCore.do_file_isvalid();
33771 break;
33772 }
33773 case FILEALLOCATE:
33774 {
33775 FFCore.do_allocate_file();
33776 break;
33777 }
33778 case FILEFLUSH:
33779 {
33780 1 FFCore.do_fflush();
33781 1 break;
33782 }
33783 case FILEREMOVE:
33784 {
33785 FFCore.do_fremove();
33786 break;
33787 }
33788 case FILEGETCHAR:
33789 {
33790 FFCore.do_file_getchar();
33791 break;
33792 }
33793 case FILEREWIND:
33794 {
33795 FFCore.do_file_rewind();
33796 break;
33797 }
33798 case FILECLEARERR:
33799 {
33800 FFCore.do_file_clearerr();
33801 break;
33802 }
33803
33804 case FILEOPEN:
33805 {
33806 1 FFCore.do_fopen(false, "rb+");
33807 1 break;
33808 }
33809 case FILECREATE:
33810 {
33811 1 FFCore.do_fopen(false, "wb+");
33812 1 break;
33813 }
33814 case FILEOPENMODE:
33815 {
33816 int32_t arrayptr = get_register(sarg2) / 10000;
33817 string mode;
33818 ArrayH::getString(arrayptr, mode, 16);
33819 FFCore.do_fopen(false, mode.c_str());
33820 break;
33821 }
33822 case FILEREADSTR:
33823 {
33824 FFCore.do_file_readstring();
33825 break;
33826 }
33827 case FILEWRITESTR:
33828 {
33829 279 FFCore.do_file_writestring();
33830 279 break;
33831 }
33832 case FILEPUTCHAR:
33833 {
33834 FFCore.do_file_putchar();
33835 break;
33836 }
33837 case FILEUNGETCHAR:
33838 {
33839 FFCore.do_file_ungetchar();
33840 break;
33841 }
33842
33843 case FILEREADCHARS:
33844 {
33845 FFCore.do_file_readchars();
33846 break;
33847 }
33848 case FILEREADBYTES:
33849 {
33850 FFCore.do_file_readbytes();
33851 break;
33852 }
33853 case FILEREADINTS:
33854 {
33855 FFCore.do_file_readints();
33856 break;
33857 }
33858 case FILEWRITECHARS:
33859 {
33860 FFCore.do_file_writechars();
33861 break;
33862 }
33863 case FILEWRITEBYTES:
33864 {
33865 FFCore.do_file_writebytes();
33866 break;
33867 }
33868 case FILEWRITEINTS:
33869 {
33870 FFCore.do_file_writeints();
33871 break;
33872 }
33873 case FILESEEK:
33874 {
33875 FFCore.do_file_seek();
33876 break;
33877 }
33878 case FILEGETERROR:
33879 {
33880 FFCore.do_file_geterr();
33881 break;
33882 }
33883 //Directory
33884 case DIRECTORYGET:
33885 {
33886 FFCore.do_directory_get();
33887 break;
33888 }
33889 case DIRECTORYRELOAD:
33890 {
33891 FFCore.do_directory_reload();
33892 break;
33893 }
33894 case DIRECTORYFREE:
33895 {
33896 FFCore.do_directory_free();
33897 break;
33898 }
33899 case DIRECTORYOWN:
33900 {
33901 if(user_dir* dr = checkDir(ri->directoryref))
33902 {
33903 own_script_object(dr, type, i);
33904 }
33905 break;
33906 }
33907 //Stack
33908 case STACKFREE:
33909 {
33910 if(user_stack* st = checkStack(ri->stackref, true))
33911 {
33912 free_script_object(st->id);
33913 }
33914 break;
33915 }
33916 case STACKOWN:
33917 {
33918 if(user_stack* st = checkStack(ri->stackref))
33919 {
33920 own_script_object(st, type, i);
33921 }
33922 break;
33923 }
33924 case STACKCLEAR:
33925 {
33926 if(user_stack* st = checkStack(ri->stackref))
33927 {
33928 st->clearStack();
33929 }
33930 break;
33931 }
33932 case STACKGET:
33933 {
33934 if(user_stack* st = checkStack(ri->stackref, true))
33935 {
33936 int32_t indx = get_register(sarg1); //NOT /10000
33937 set_register(sarg1, st->get(indx)); //NOT *10000
33938 }
33939 else set_register(sarg1, 0L);
33940 break;
33941 }
33942 case STACKSET:
33943 {
33944 if(user_stack* st = checkStack(ri->stackref, true))
33945 {
33946 int32_t indx = get_register(sarg1); //NOT /10000
33947 int32_t val = get_register(sarg2); //NOT /10000
33948 st->set(indx, val); //NOT *10000
33949 }
33950 break;
33951 }
33952 case STACKPOPBACK:
33953 {
33954 if(user_stack* st = checkStack(ri->stackref, true))
33955 {
33956 set_register(sarg1, st->pop_back()); //NOT *10000
33957 }
33958 else set_register(sarg1, 0L);
33959 break;
33960 }
33961 case STACKPOPFRONT:
33962 {
33963 if(user_stack* st = checkStack(ri->stackref, true))
33964 {
33965 set_register(sarg1, st->pop_front()); //NOT *10000
33966 }
33967 else set_register(sarg1, 0L);
33968 break;
33969 }
33970 case STACKPEEKBACK:
33971 {
33972 if(user_stack* st = checkStack(ri->stackref, true))
33973 {
33974 set_register(sarg1, st->peek_back()); //NOT *10000
33975 }
33976 else set_register(sarg1, 0L);
33977 break;
33978 }
33979 case STACKPEEKFRONT:
33980 {
33981 if(user_stack* st = checkStack(ri->stackref, true))
33982 {
33983 set_register(sarg1, st->peek_front()); //NOT *10000
33984 }
33985 else set_register(sarg1, 0L);
33986 break;
33987 }
33988 case STACKPUSHBACK:
33989 {
33990 if(user_stack* st = checkStack(ri->stackref, true))
33991 {
33992 int32_t val = get_register(sarg1); //NOT /10000
33993 st->push_back(val);
33994 }
33995 break;
33996 }
33997 case STACKPUSHFRONT:
33998 {
33999 if(user_stack* st = checkStack(ri->stackref, true))
34000 {
34001 int32_t val = get_register(sarg1); //NOT /10000
34002 st->push_front(val);
34003 }
34004 break;
34005 }
34006
34007 //Module
34008 case MODULEGETIC:
34009 {
34010
34011 int32_t buf_pointer = SH::get_arg(sarg1, false) / 10000;
34012 int32_t element = SH::get_arg(sarg2, false) / 10000;
34013
34014 if ( ((unsigned)element) > 511 )
34015 {
34016 Z_scripterrlog("Illegal itemclass supplied to ZInfo->GetItemClass().\nLegal values are 1 to 511.\n");
34017 }
34018 else
34019 {
34020 char buffer[256] = {0};
34021 strcpy(buffer,ZI.getItemClassName(element));
34022 buffer[255] = '\0';
34023 if(ArrayH::setArray(buf_pointer, buffer) == SH::_Overflow)
34024 {
34025 Z_scripterrlog("Dest string supplied to 'Module->GetItemClass()' is not large enough\n");
34026 }
34027 }
34028
34029 break;
34030 }
34031
34032 //{ Randgen Stuff
34033 case RNGRAND1:
34034 if(user_rng* r = checkRNG(ri->rngref))
34035 {
34036 ri->d[rEXP1] = r->rand(214748, -214748)*10000L;
34037 }
34038 else ri->d[rEXP1] = -10000L;
34039 break;
34040 case RNGRAND2:
34041
1/2
✓ Branch 0 taken 1338 times.
✗ Branch 1 not taken.
1338 if(user_rng* r = checkRNG(ri->rngref))
34042 {
34043 1338 set_register(sarg1,r->rand(get_register(sarg1)/10000L)*10000L);
34044 1338 }
34045 else set_register(sarg1,-10000L);
34046 1338 break;
34047 case RNGRAND3:
34048
1/2
✓ Branch 0 taken 448056 times.
✗ Branch 1 not taken.
448056 if(user_rng* r = checkRNG(ri->rngref))
34049 {
34050 448056 set_register(sarg1,r->rand(get_register(sarg1)/10000L, get_register(sarg2)/10000L)* 10000L);
34051 448056 }
34052 else set_register(sarg1,-10000L);
34053 448056 break;
34054 case RNGLRAND1:
34055 if(user_rng* r = checkRNG(ri->rngref))
34056 {
34057 ri->d[rEXP1] = r->rand();
34058 }
34059 else ri->d[rEXP1] = -10000L;
34060 break;
34061 case RNGLRAND2:
34062 if(user_rng* r = checkRNG(ri->rngref))
34063 {
34064 ri->d[rEXP1] = r->rand(get_register(sarg1));
34065 }
34066 else ri->d[rEXP1] = -10000L;
34067 break;
34068 case RNGLRAND3:
34069 if(user_rng* r = checkRNG(ri->rngref))
34070 {
34071 ri->d[rEXP1] = r->rand(get_register(sarg1), get_register(sarg2));
34072 }
34073 else ri->d[rEXP1] = -10000L;
34074 break;
34075 case RNGSEED:
34076
1/2
✓ Branch 0 taken 73 times.
✗ Branch 1 not taken.
73 if(user_rng* r = checkRNG(ri->rngref))
34077 {
34078 73 r->srand(get_register(sarg1));
34079 73 }
34080 73 break;
34081 case RNGRSEED:
34082 if(user_rng* r = checkRNG(ri->rngref))
34083 {
34084 ri->d[rEXP1] = r->srand();
34085 }
34086 else ri->d[rEXP1] = -10000;
34087 break;
34088 case RNGFREE:
34089
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(user_rng* r = checkRNG(ri->rngref, true))
34090 {
34091 6 free_script_object(r->id);
34092 6 }
34093 6 break;
34094 case RNGOWN:
34095
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(user_rng* r = checkRNG(ri->rngref, false))
34096 {
34097 8 own_script_object(r, type, i);
34098 8 }
34099 8 break;
34100 //}
34101 case LOADGENERICDATA:
34102 137106 FFCore.do_loadgenericdata(false); break;
34103 case RUNGENFRZSCR:
34104 {
34105 10 bool r = FFCore.runGenericFrozenEngine(word(ri->genericdataref));
34106 10 set_register(sarg1, r ? 10000L : 0L);
34107 10 break;
34108 }
34109
34110 ///----------------------------------------------------------------------------------------------------//
34111
34112 case SUBDATA_GET_NAME:
34113 {
34114 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
34115 {
34116 auto aptr = get_register(sarg1) / 10000;
34117 if(ArrayH::setArray(aptr, sub->name, true) == SH::_Overflow)
34118 Z_scripterrlog("Array supplied to 'subscreendata->GetName()' not large enough,"
34119 " and couldn't be resized!\n");
34120 }
34121 break;
34122 }
34123 case SUBDATA_SET_NAME:
34124 {
34125 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
34126 {
34127 auto aptr = get_register(sarg1) / 10000;
34128 ArrayH::getString(aptr, sub->name);
34129 }
34130 break;
34131 }
34132 case SUBDATA_SWAP_PAGES:
34133 {
34134 ri->subdataref = SH::read_stack(ri->sp+2);
34135 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
34136 {
34137 int p1 = SH::read_stack(ri->sp+1) / 10000;
34138 int p2 = SH::read_stack(ri->sp+0) / 10000;
34139 if(unsigned(p1) >= sub->pages.size())
34140 Z_scripterrlog("Invalid page index '%d' passed to subscreendata->SwapPages()\n", p1);
34141 else if(unsigned(p2) >= sub->pages.size())
34142 Z_scripterrlog("Invalid page index '%d' passed to subscreendata->SwapPages()\n", p2);
34143 else sub->swap_pages(p1,p2);
34144 }
34145 break;
34146 }
34147 case SUBPAGE_SWAP_WIDG:
34148 {
34149 ri->subpageref = SH::read_stack(ri->sp+2);
34150 if(SubscrPage* pg = checkSubPage(ri->subpageref))
34151 {
34152 int p1 = SH::read_stack(ri->sp+1) / 10000;
34153 int p2 = SH::read_stack(ri->sp+0) / 10000;
34154 if(unsigned(p1) >= pg->size())
34155 Z_scripterrlog("Invalid page index '%d' passed to subscreenpage->SwapWidgets()\n", p1);
34156 else if(unsigned(p2) >= pg->size())
34157 Z_scripterrlog("Invalid page index '%d' passed to subscreenpage->SwapWidgets()\n", p2);
34158 else pg->swap_widg(p1,p2);
34159 }
34160 break;
34161 }
34162 case SUBPAGE_FIND_WIDGET:
34163 {
34164 14870 ri->d[rEXP1] = 0;
34165 14870 ri->subpageref = SH::read_stack(ri->sp+1);
34166
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14870 times.
14870 if(SubscrPage* pg = checkSubPage(ri->subpageref, sstACTIVE))
34167 {
34168 14870 int cursorpos = SH::read_stack(ri->sp+0) / 10000;
34169
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14870 times.
14870 if(auto* widg = pg->get_widg_pos(cursorpos,false))
34170 {
34171 14870 auto q = pg->widget_index(widg);
34172
1/2
✓ Branch 0 taken 14870 times.
✗ Branch 1 not taken.
14870 if(q > -1)
34173 {
34174 44610 auto [sub,ty,pgid,_ind] = from_subref(ri->subpageref);
34175 44610 ri->d[rEXP1] = get_subref(sub,ty,pgid,q);
34176 14870 }
34177 14870 }
34178 14870 }
34179 14870 break;
34180 }
34181 case SUBPAGE_FIND_WIDGET_BY_LABEL:
34182 {
34183 17877 ri->d[rEXP1] = 0;
34184 17877 ri->subpageref = SH::read_stack(ri->sp+1);
34185
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17877 times.
17877 if(SubscrPage* pg = checkSubPage(ri->subpageref))
34186 {
34187 17877 int aptr = SH::read_stack(ri->sp+0) / 10000;
34188 17877 std::string lbl;
34189
1/2
✓ Branch 0 taken 17877 times.
✗ Branch 1 not taken.
17877 ArrayH::getString(aptr, lbl);
34190
1/2
✓ Branch 0 taken 17877 times.
✗ Branch 1 not taken.
17877 if(lbl.size())
34191 {
34192
1/2
✓ Branch 0 taken 17877 times.
✗ Branch 1 not taken.
17877 auto q = pg->find_label_index(lbl);
34193
2/2
✓ Branch 0 taken 5703 times.
✓ Branch 1 taken 12174 times.
17877 if(q > -1)
34194 {
34195 36522 auto [sub,ty,pgid,_ind] = from_subref(ri->subpageref);
34196 36522 ri->d[rEXP1] = get_subref(sub,ty,pgid,q);
34197 12174 }
34198 17877 }
34199 17877 }
34200 17877 break;
34201 }
34202 case SUBPAGE_MOVE_SEL:
34203 {
34204 #define SUBSEL_FLAG_NO_NONEQUIP 0x01
34205 #define SUBSEL_FLAG_NEED_ITEM 0x02
34206 ri->subpageref = SH::read_stack(ri->sp+3);
34207 if(SubscrPage* pg = checkSubPage(ri->subpageref))
34208 {
34209 int flags = SH::read_stack(ri->sp+0) / 10000;
34210 int dir = SH::read_stack(ri->sp+1) / 10000;
34211 int pos = SH::read_stack(ri->sp+2) / 10000;
34212 switch(dir)
34213 {
34214 case up:
34215 dir = SEL_UP;
34216 break;
34217 case down:
34218 dir = SEL_DOWN;
34219 break;
34220 case left:
34221 dir = SEL_LEFT;
34222 break;
34223 case right: default:
34224 dir = SEL_RIGHT;
34225 break;
34226 }
34227
34228 auto newpos = pg->movepos_legacy(dir, (pos<<8)|pg->getIndex(),
34229 255, 255, 255, flags&SUBSEL_FLAG_NO_NONEQUIP,
34230 flags&SUBSEL_FLAG_NEED_ITEM, true) >> 8;
34231 ri->d[rEXP1] = 10000*newpos;
34232 }
34233 break;
34234 }
34235 case SUBPAGE_NEW_WIDG:
34236 {
34237 ri->subpageref = SH::read_stack(ri->sp+1);
34238 if(SubscrPage* pg = checkSubPage(ri->subpageref))
34239 {
34240 if(pg->size() == 0x2000)
34241 break; //Page is full!
34242 int ty = SH::read_stack(ri->sp+0) / 10000;
34243 if(auto* widg = SubscrWidget::newType(ty))
34244 {
34245 widg->posflags = sspUP | sspDOWN | sspSCROLLING;
34246 widg->w = 1;
34247 widg->h = 1;
34248 pg->push_back(widg);
34249 auto [sub,ty,pgid,_ind] = from_subref(ri->subpageref);
34250 ri->d[rEXP1] = get_subref(sub,ty,pgid,pg->size()-1);
34251 }
34252 else Z_scripterrlog("Invalid type %d passed to subscreenpage->CreateWidget()\n",ty);
34253 }
34254 break;
34255 }
34256 case SUBPAGE_DELETE:
34257 {
34258 if(SubscrPage* pg = checkSubPage(ri->subpageref))
34259 {
34260 auto [sub,_ty] = load_subdata(ri->subpageref);
34261 sub->delete_page(pg->getIndex());
34262 }
34263 break;
34264 }
34265 case SUBWIDG_GET_SELTEXT_OVERRIDE:
34266 {
34267 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
34268 {
34269 auto aptr = get_register(sarg1) / 10000;
34270 if(ArrayH::setArray(aptr, widg->override_text, true) == SH::_Overflow)
34271 Z_scripterrlog("Array supplied to 'subscreenwidget->GetSelTextOverride()' not large enough,"
34272 " and couldn't be resized!\n");
34273 }
34274 break;
34275 }
34276 case SUBWIDG_SET_SELTEXT_OVERRIDE:
34277 {
34278 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
34279 {
34280 auto aptr = get_register(sarg1) / 10000;
34281 ArrayH::getString(aptr, widg->override_text);
34282 }
34283 break;
34284 }
34285 case SUBWIDG_GET_LABEL:
34286 {
34287
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
34288 {
34289 828 auto aptr = get_register(sarg1) / 10000;
34290
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(ArrayH::setArray(aptr, widg->label, true) == SH::_Overflow)
34291 Z_scripterrlog("Array supplied to 'subscreenwidget->GetLabel()' not large enough,"
34292 " and couldn't be resized!\n");
34293 828 }
34294 828 break;
34295 }
34296 case SUBWIDG_SET_LABEL:
34297 {
34298 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
34299 {
34300 auto aptr = get_register(sarg1) / 10000;
34301 ArrayH::getString(aptr, widg->label);
34302 }
34303 break;
34304 }
34305 case SUBWIDG_CHECK_CONDITIONS:
34306 {
34307 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
34308 {
34309 set_register(sarg1, widg->check_conditions() ? 10000 : 0);
34310 }
34311 break;
34312 }
34313 case SUBWIDG_CHECK_VISIBLE:
34314 {
34315 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
34316 {
34317 extern int current_subscr_pos;
34318 set_register(sarg1, widg->visible(current_subscr_pos, game->should_show_time()) ? 10000 : 0);
34319 }
34320 break;
34321 }
34322 case SUBWIDG_TY_GETTEXT:
34323 {
34324 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
34325 {
34326 std::string const* str = nullptr;
34327 byte ty = widg->getType();
34328 switch(ty)
34329 {
34330 case widgTEXT:
34331 str = &((SW_Text*)widg)->text;
34332 break;
34333 case widgTEXTBOX:
34334 str = &((SW_TextBox*)widg)->text;
34335 break;
34336 default:
34337 bad_subwidg_type(true, ty);
34338 break;
34339 }
34340 if(str)
34341 {
34342 auto aptr = get_register(sarg1) / 10000;
34343 if(ArrayH::setArray(aptr, *str, true) == SH::_Overflow)
34344 Z_scripterrlog("Array supplied to 'subscreenwidget->GetText()' not large enough,"
34345 " and couldn't be resized!\n");
34346 }
34347 }
34348 break;
34349 }
34350 case SUBWIDG_TY_SETTEXT:
34351 {
34352
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76234 times.
76234 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
34353 {
34354 76234 std::string* str = nullptr;
34355 76234 byte ty = widg->getType();
34356
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 68852 times.
✓ Branch 2 taken 7382 times.
76234 switch(ty)
34357 {
34358 case widgTEXT:
34359 68852 str = &((SW_Text*)widg)->text;
34360 68852 break;
34361 case widgTEXTBOX:
34362 7382 str = &((SW_TextBox*)widg)->text;
34363 7382 break;
34364 default:
34365 bad_subwidg_type(true, ty);
34366 break;
34367 }
34368
1/2
✓ Branch 0 taken 76234 times.
✗ Branch 1 not taken.
76234 if(str)
34369 {
34370 76234 auto aptr = get_register(sarg1) / 10000;
34371 76234 ArrayH::getString(aptr, *str);
34372 76234 }
34373 76234 }
34374 76234 break;
34375 }
34376
34377 case REF_INC:
34378 {
34379 1120 int offset = ri->d[rSFRAME] + sarg1;
34380
1/2
✓ Branch 0 taken 1120 times.
✗ Branch 1 not taken.
1120 if (!ri->stack_pos_is_object.contains(offset))
34381 {
34382 assert(false);
34383 break;
34384 }
34385
34386 1120 uint32_t id = SH::read_stack(offset);
34387 1120 script_object_ref_inc(id);
34388 1120 break;
34389 }
34390 case REF_DEC:
34391 {
34392 int offset = ri->d[rSFRAME] + sarg1;
34393 if (!ri->stack_pos_is_object.contains(offset))
34394 {
34395 assert(false);
34396 break;
34397 }
34398
34399 uint32_t id = SH::read_stack(offset);
34400 script_object_ref_dec(id);
34401 break;
34402 }
34403 case REF_AUTORELEASE:
34404 {
34405 10 uint32_t id = get_register(sarg1);
34406 10 script_object_autorelease_pool.push_back(id);
34407 10 script_object_ref_inc(id);
34408 10 break;
34409 }
34410 case REF_COUNT:
34411 {
34412
1/2
✓ Branch 0 taken 150 times.
✗ Branch 1 not taken.
150 if (!use_testingst_start)
34413 {
34414 Z_scripterrlog("RefCount can only be used in test mode\n");
34415 break;
34416 }
34417
34418 150 uint32_t id = get_register(sarg1);
34419 150 auto object = get_script_object(id);
34420
2/2
✓ Branch 0 taken 140 times.
✓ Branch 1 taken 10 times.
150 int count = object ? object->ref_count : -1;
34421 150 set_register(sarg1, count);
34422 150 break;
34423 }
34424 case MARK_TYPE_STACK:
34425 {
34426 1120 int offset = ri->d[rSFRAME] + sarg2;
34427
1/2
✓ Branch 0 taken 1120 times.
✗ Branch 1 not taken.
1120 if (offset < 0 || offset >= MAX_SCRIPT_REGISTERS)
34428 {
34429 assert(false);
34430 break;
34431 }
34432
1/2
✓ Branch 0 taken 1120 times.
✗ Branch 1 not taken.
1120 if (sarg1 < 0 || sarg1 > 1)
34433 {
34434 assert(false);
34435 break;
34436 }
34437
34438
1/2
✓ Branch 0 taken 1120 times.
✗ Branch 1 not taken.
1120 if (sarg1)
34439 1120 ri->stack_pos_is_object.insert(offset);
34440 else
34441 ri->stack_pos_is_object.erase(offset);
34442 1120 break;
34443 }
34444 case MARK_TYPE_REG:
34445 {
34446 // Currently only marking globals as objects is supported.
34447
1/2
✓ Branch 0 taken 348 times.
✗ Branch 1 not taken.
348 if (!(sarg1 >= GD(0) && sarg1 <= GD(MAX_SCRIPT_REGISTERS)))
34448 {
34449 assert(false);
34450 break;
34451 }
34452
1/2
✓ Branch 0 taken 348 times.
✗ Branch 1 not taken.
348 if (!(sarg2 >= 0 && sarg2 <= (int)script_object_type::last))
34453 {
34454 assert(false);
34455 break;
34456 }
34457
34458 348 int index = sarg1 - GD(0);
34459 348 game->global_d_types[index] = (script_object_type)sarg2;
34460 348 break;
34461 }
34462 case REF_REMOVE:
34463 {
34464 int offset = ri->d[rSFRAME] + sarg1;
34465 script_remove_object_ref(offset);
34466 break;
34467 }
34468 case GC:
34469 {
34470
1/2
✓ Branch 0 taken 140 times.
✗ Branch 1 not taken.
140 if (!use_testingst_start)
34471 {
34472 Z_error_fatal("GC can only be used in test mode\n");
34473 break;
34474 }
34475
34476 140 run_gc();
34477 140 break;
34478 }
34479 case SET_OBJECT:
34480 {
34481
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!(sarg1 >= GD(0) && sarg1 <= GD(MAX_SCRIPT_REGISTERS)))
34482 {
34483 assert(false);
34484 break;
34485 }
34486
34487 8 int value = get_register(sarg2);
34488 8 int index = sarg1-GD(0);
34489
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 assert(game->global_d_types[index] != script_object_type::none);
34490 8 script_object_ref_inc(value);
34491 8 script_object_ref_dec(game->global_d[index]);
34492 8 game->global_d[index] = value;
34493 8 break;
34494 }
34495
34496 default:
34497 {
34498
1/2
✓ Branch 0 taken 1180630 times.
✗ Branch 1 not taken.
1180630 if (auto r = scripting_engine_run_command(scommand))
34499 {
34500
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1180630 times.
1180630 if (*r != RUNSCRIPT_OK)
34501 return *r;
34502 1180630 break;
34503 }
34504
34505 Z_scripterrlog("Invalid ZASM command %lu reached; terminating\n", scommand);
34506 hit_invalid_zasm = true;
34507 scommand = 0xFFFF;
34508 break;
34509 }
34510 }
34511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1147784551 times.
1147784551 if(earlyretval == RUNSCRIPT_SELFDELETE)
34512 {
34513 earlyretval = -1;
34514 return RUNSCRIPT_SELFDELETE;
34515 }
34516
1/2
✓ Branch 0 taken 1147784551 times.
✗ Branch 1 not taken.
1147784551 if (ri->sp >= MAX_SCRIPT_REGISTERS)
34517 {
34518 if (old_script_funcrun)
34519 return RUNSCRIPT_OK;
34520 Z_scripterrlog("Stack over/underflow caused by command %d!\n", scommand);
34521 }
34522
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1147784551 times.
1147784551 if(hit_invalid_zasm) break;
34523
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1147784551 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1147784551 if(old_script_funcrun && (ri->pc == MAX_PC || scommand == RETURN))
34524 return RUNSCRIPT_OK;
34525
34526
2/2
✓ Branch 0 taken 1144870749 times.
✓ Branch 1 taken 2913802 times.
1147784551 if (type == ScriptType::Combo)
34527 {
34528
1/2
✓ Branch 0 taken 2913802 times.
✗ Branch 1 not taken.
2913802 if(combopos_modified == i)
34529 {
34530 //Combo changed! Abort script!
34531 return RUNSCRIPT_OK;
34532 }
34533 2913802 }
34534
2/2
✓ Branch 0 taken 82823 times.
✓ Branch 1 taken 1147701728 times.
1147784551 if(scommand != 0xFFFF)
34535 {
34536
2/2
✓ Branch 0 taken 1147699826 times.
✓ Branch 1 taken 1902 times.
1147701728 if(increment) ri->pc++;
34537 1902 else increment = true;
34538
1/2
✓ Branch 0 taken 1147701728 times.
✗ Branch 1 not taken.
1147701728 if ( ri->pc == MAX_PC ) //rolled over from overflow?
34539 {
34540 Z_scripterrlog("Script PC overflow! Too many ZASM lines?\n");
34541 ri->pc = curscript->pc;
34542 scommand = 0xFFFF;
34543 }
34544 1147701728 }
34545
34546
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1147784551 times.
1147784551 if(earlyretval > -1) //Should this be below the 'commands_run += 1'? Unsure. -Em
34547 {
34548 auto v = earlyretval;
34549 earlyretval = -1;
34550 return earlyretval;
34551 }
34552
34553 // If running a JIT compiled script, we're only here to do a few commands.
34554 1147784551 commands_run += 1;
34555
4/4
✓ Branch 0 taken 1147737420 times.
✓ Branch 1 taken 47131 times.
✓ Branch 2 taken 1139146703 times.
✓ Branch 3 taken 8590717 times.
1147784551 if (is_jitted && commands_run == jitted_uncompiled_command_count) break;
34556 }
34557
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 1165699657 times.
1165699777 if(script_funcrun) return RUNSCRIPT_OK;
34558
34559
2/2
✓ Branch 0 taken 1165699630 times.
✓ Branch 1 taken 27 times.
1165699657 if(!scriptCanSave)
34560 27 scriptCanSave=true;
34561
34562
2/2
✓ Branch 0 taken 1159651592 times.
✓ Branch 1 taken 6048065 times.
1165699657 if(scommand == WAITDRAW)
34563 {
34564
2/5
✗ Branch 0 not taken.
✓ Branch 1 taken 6031783 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 16282 times.
6048065 switch(type)
34565 {
34566 case ScriptType::Global:
34567 case ScriptType::Hero:
34568 case ScriptType::DMap:
34569 case ScriptType::OnMap:
34570 case ScriptType::ScriptedPassiveSubscreen:
34571 case ScriptType::ScriptedActiveSubscreen:
34572 case ScriptType::Screen:
34573 case ScriptType::Combo:
34574 case ScriptType::NPC:
34575 case ScriptType::Lwpn:
34576 case ScriptType::Ewpn:
34577 case ScriptType::ItemSprite:
34578 6031783 FFCore.waitdraw(type, i) = true;
34579 6031783 break;
34580
34581 case ScriptType::Item:
34582 {
34583 if (!get_qr(qr_NOITEMWAITDRAW))
34584 {
34585 FFCore.waitdraw(ScriptType::Item, i) = true;
34586 }
34587 break;
34588 }
34589
34590 case ScriptType::FFC:
34591 {
34592
2/2
✓ Branch 0 taken 1221 times.
✓ Branch 1 taken 15061 times.
16282 if ( !(get_qr(qr_NOFFCWAITDRAW)) )
34593 {
34594 15061 FFCore.waitdraw(ScriptType::FFC, i) = true;
34595 15061 }
34596 else
34597 {
34598 1221 Z_scripterrlog("Waitdraw cannot be used in script type: %s\n", "ffc, with Script Rule 'No FFC Waitdraw() enabled!");
34599 }
34600 16282 break;
34601 }
34602
34603 case ScriptType::Generic:
34604 case ScriptType::GenericFrozen:
34605 case ScriptType::EngineSubscreen:
34606 //No Waitdraw
34607 break;
34608
34609 default:
34610 Z_scripterrlog("Waitdraw cannot be used in script type: %s\n", ScriptTypeToString(type));
34611 break;
34612 }
34613 6048065 }
34614
34615
2/2
✓ Branch 0 taken 82728 times.
✓ Branch 1 taken 1165616929 times.
1165699657 if(scommand == 0xFFFF) //Quit/command list end reached/bad command
34616 {
34617 82728 script_exit_cleanup(no_dealloc);
34618 82728 return RUNSCRIPT_STOPPED;
34619 }
34620 else
34621 1165616929 ri->pc++;
34622
34623
2/2
✓ Branch 0 taken 26552922 times.
✓ Branch 1 taken 1139064007 times.
1165616929 if(jit_waiting_nop)
34624 26552922 return RUNSCRIPT_STOPPED;
34625
34626 1139064007 return RUNSCRIPT_OK;
34627 1165699795 }
34628
34629 330 script_data* load_scrdata(ScriptType type, word script, int32_t i)
34630 {
34631
2/15
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 90 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 240 times.
✗ Branch 14 not taken.
330 switch(type)
34632 {
34633 case ScriptType::FFC:
34634 return ffscripts[script];
34635 case ScriptType::NPC:
34636 return guyscripts[guys.getByUID(i)->script];
34637 case ScriptType::Lwpn:
34638 return lwpnscripts[Lwpns.getByUID(i)->weaponscript];
34639 case ScriptType::Ewpn:
34640 return ewpnscripts[Ewpns.getByUID(i)->weaponscript];
34641 case ScriptType::ItemSprite:
34642 return itemspritescripts[items.getByUID(i)->script];
34643 case ScriptType::Item:
34644 return itemscripts[script];
34645 case ScriptType::Global:
34646 return globalscripts[script];
34647 case ScriptType::Generic:
34648 case ScriptType::GenericFrozen:
34649 240 return genericscripts[script];
34650 case ScriptType::Hero:
34651 return playerscripts[script];
34652 case ScriptType::DMap:
34653 return dmapscripts[script];
34654 case ScriptType::OnMap:
34655 case ScriptType::ScriptedActiveSubscreen:
34656 case ScriptType::ScriptedPassiveSubscreen:
34657 return dmapscripts[script];
34658 case ScriptType::Screen:
34659 return screenscripts[script];
34660 case ScriptType::Combo:
34661 return comboscripts[script];
34662 case ScriptType::EngineSubscreen:
34663 return subscreenscripts[script];
34664 }
34665 90 return nullptr;
34666 330 }
34667
34668 //This keeps ffc scripts running beyond the first frame.
34669 14290710 int32_t ffscript_engine(const bool preload)
34670 {
34671
2/2
✓ Branch 0 taken 14256243 times.
✓ Branch 1 taken 34467 times.
14290710 if(preload)
34672 {
34673 34467 throwGenScriptEvent(GENSCR_EVENT_FFC_PRELOAD);
34674 34467 }
34675
2/2
✓ Branch 0 taken 14288124 times.
✓ Branch 1 taken 2586 times.
14290710 if (!FFCore.system_suspend[susptFFCSCRIPTS])
34676 {
34677 //run screen script, first
34678
2/2
✓ Branch 0 taken 12464231 times.
✓ Branch 1 taken 1823893 times.
14288124 if ( FFCore.getQuestHeaderInfo(vZelda) >= 0x255 )
34679 {
34680 4036862 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
34681
4/4
✓ Branch 0 taken 5135 times.
✓ Branch 1 taken 2207834 times.
✓ Branch 2 taken 5056 times.
✓ Branch 3 taken 2202778 times.
2212969 if ((preload && scr->preloadscript) || !preload)
34682 {
34683
3/4
✓ Branch 0 taken 50436 times.
✓ Branch 1 taken 2157477 times.
✓ Branch 2 taken 50436 times.
✗ Branch 3 not taken.
2207913 if ( scr->script > 0 && FFCore.doscript(ScriptType::Screen, scr->screen) )
34684 {
34685 50436 ZScriptVersion::RunScript(ScriptType::Screen, scr->script, scr->screen);
34686 50436 }
34687 2207913 }
34688 2212969 });
34689 1823893 }
34690
34691 453507957 for_every_ffc([&](const ffc_handle_t& ffc_handle) {
34692
2/2
✓ Branch 0 taken 11252367 times.
✓ Branch 1 taken 427967466 times.
439219833 if(ffc_handle.ffc->script == 0)
34693 427967466 return;
34694
34695
4/4
✓ Branch 0 taken 12920 times.
✓ Branch 1 taken 11239447 times.
✓ Branch 2 taken 10120 times.
✓ Branch 3 taken 2800 times.
11252367 if(preload && !(ffc_handle.ffc->flags&ffc_preload))
34696 10120 return;
34697
34698
4/4
✓ Branch 0 taken 11237688 times.
✓ Branch 1 taken 4559 times.
✓ Branch 2 taken 11152607 times.
✓ Branch 3 taken 85081 times.
11242247 if((ffc_handle.ffc->flags&ffc_ignoreholdup)==0 && Hero.getHoldClk()>0)
34699 85081 return;
34700
34701 11157166 ZScriptVersion::RunScript(ScriptType::FFC, ffc_handle.ffc->script, ffc_handle.id);
34702 439219833 });
34703 14288124 }
34704
34705
34706 14290710 return 0;
34707 }
34708
34709
34710
34711 ///----------------------------------------------------------------------------------------------------
34712
34713 784 void FFScript::user_files_init()
34714 {
34715 784 user_files.clear();
34716 784 }
34717
34718 784 void FFScript::user_dirs_init()
34719 {
34720 784 user_dirs.clear();
34721 784 }
34722 784 void FFScript::user_objects_init()
34723 {
34724 784 ::user_object_init();
34725 784 }
34726
34727 784 void FFScript::user_stacks_init()
34728 {
34729 784 user_stacks.clear();
34730 784 }
34731
34732 1094 void FFScript::user_rng_init()
34733 {
34734 1094 user_rngs.clear();
34735
2/2
✓ Branch 0 taken 280064 times.
✓ Branch 1 taken 1094 times.
281158 for(int32_t q = 0; q < MAX_USER_RNGS; ++q)
34736 {
34737 280064 replay_register_rng(&script_rnggens[q]);
34738
34739 // Just to seed it.
34740 280064 user_rng rng;
34741 280064 rng.set_gen(&script_rnggens[q]);
34742 280064 }
34743 1094 }
34744
34745 784 void FFScript::user_paldata_init()
34746 {
34747 784 user_paldatas.clear();
34748 784 }
34749
34750 413 void FFScript::user_websockets_init()
34751 {
34752 413 websocket_init();
34753 413 }
34754
34755 // Gotten from 'https://fileinfo.com/filetypes/executable'
34756
187/376
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 403 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 403 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 403 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 403 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 403 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 403 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 403 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 403 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 403 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 403 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 403 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 403 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 403 times.
✗ Branch 31 not taken.
✓ Branch 32 taken 403 times.
✗ Branch 33 not taken.
✓ Branch 34 taken 403 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 403 times.
✗ Branch 37 not taken.
✓ Branch 38 taken 403 times.
✗ Branch 39 not taken.
✓ Branch 40 taken 403 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 403 times.
✗ Branch 43 not taken.
✓ Branch 44 taken 403 times.
✗ Branch 45 not taken.
✓ Branch 46 taken 403 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 403 times.
✗ Branch 49 not taken.
✓ Branch 50 taken 403 times.
✗ Branch 51 not taken.
✓ Branch 52 taken 403 times.
✗ Branch 53 not taken.
✓ Branch 54 taken 403 times.
✗ Branch 55 not taken.
✓ Branch 56 taken 403 times.
✗ Branch 57 not taken.
✓ Branch 58 taken 403 times.
✗ Branch 59 not taken.
✓ Branch 60 taken 403 times.
✗ Branch 61 not taken.
✓ Branch 62 taken 403 times.
✗ Branch 63 not taken.
✓ Branch 64 taken 403 times.
✗ Branch 65 not taken.
✓ Branch 66 taken 403 times.
✗ Branch 67 not taken.
✓ Branch 68 taken 403 times.
✗ Branch 69 not taken.
✓ Branch 70 taken 403 times.
✗ Branch 71 not taken.
✓ Branch 72 taken 403 times.
✗ Branch 73 not taken.
✓ Branch 74 taken 403 times.
✗ Branch 75 not taken.
✓ Branch 76 taken 403 times.
✗ Branch 77 not taken.
✓ Branch 78 taken 403 times.
✗ Branch 79 not taken.
✓ Branch 80 taken 403 times.
✗ Branch 81 not taken.
✓ Branch 82 taken 403 times.
✗ Branch 83 not taken.
✓ Branch 84 taken 403 times.
✗ Branch 85 not taken.
✓ Branch 86 taken 403 times.
✗ Branch 87 not taken.
✓ Branch 88 taken 403 times.
✗ Branch 89 not taken.
✓ Branch 90 taken 403 times.
✗ Branch 91 not taken.
✓ Branch 92 taken 403 times.
✗ Branch 93 not taken.
✓ Branch 94 taken 403 times.
✗ Branch 95 not taken.
✓ Branch 96 taken 403 times.
✗ Branch 97 not taken.
✓ Branch 98 taken 403 times.
✗ Branch 99 not taken.
✓ Branch 100 taken 403 times.
✗ Branch 101 not taken.
✓ Branch 102 taken 403 times.
✗ Branch 103 not taken.
✓ Branch 104 taken 403 times.
✗ Branch 105 not taken.
✓ Branch 106 taken 403 times.
✗ Branch 107 not taken.
✓ Branch 108 taken 403 times.
✗ Branch 109 not taken.
✓ Branch 110 taken 403 times.
✗ Branch 111 not taken.
✓ Branch 112 taken 403 times.
✗ Branch 113 not taken.
✓ Branch 114 taken 403 times.
✗ Branch 115 not taken.
✓ Branch 116 taken 403 times.
✗ Branch 117 not taken.
✓ Branch 118 taken 403 times.
✗ Branch 119 not taken.
✓ Branch 120 taken 403 times.
✗ Branch 121 not taken.
✓ Branch 122 taken 403 times.
✗ Branch 123 not taken.
✓ Branch 124 taken 403 times.
✗ Branch 125 not taken.
✓ Branch 126 taken 403 times.
✗ Branch 127 not taken.
✓ Branch 128 taken 403 times.
✗ Branch 129 not taken.
✓ Branch 130 taken 403 times.
✗ Branch 131 not taken.
✓ Branch 132 taken 403 times.
✗ Branch 133 not taken.
✓ Branch 134 taken 403 times.
✗ Branch 135 not taken.
✓ Branch 136 taken 403 times.
✗ Branch 137 not taken.
✓ Branch 138 taken 403 times.
✗ Branch 139 not taken.
✓ Branch 140 taken 403 times.
✗ Branch 141 not taken.
✓ Branch 142 taken 403 times.
✗ Branch 143 not taken.
✓ Branch 144 taken 403 times.
✗ Branch 145 not taken.
✓ Branch 146 taken 403 times.
✗ Branch 147 not taken.
✓ Branch 148 taken 403 times.
✗ Branch 149 not taken.
✓ Branch 150 taken 403 times.
✗ Branch 151 not taken.
✓ Branch 152 taken 403 times.
✗ Branch 153 not taken.
✓ Branch 154 taken 403 times.
✗ Branch 155 not taken.
✓ Branch 156 taken 403 times.
✗ Branch 157 not taken.
✓ Branch 158 taken 403 times.
✗ Branch 159 not taken.
✓ Branch 160 taken 403 times.
✗ Branch 161 not taken.
✓ Branch 162 taken 403 times.
✗ Branch 163 not taken.
✓ Branch 164 taken 403 times.
✗ Branch 165 not taken.
✓ Branch 166 taken 403 times.
✗ Branch 167 not taken.
✓ Branch 168 taken 403 times.
✗ Branch 169 not taken.
✓ Branch 170 taken 403 times.
✗ Branch 171 not taken.
✓ Branch 172 taken 403 times.
✗ Branch 173 not taken.
✓ Branch 174 taken 403 times.
✗ Branch 175 not taken.
✓ Branch 176 taken 403 times.
✗ Branch 177 not taken.
✓ Branch 178 taken 403 times.
✗ Branch 179 not taken.
✓ Branch 180 taken 403 times.
✗ Branch 181 not taken.
✓ Branch 182 taken 403 times.
✗ Branch 183 not taken.
✓ Branch 184 taken 403 times.
✗ Branch 185 not taken.
✓ Branch 186 taken 403 times.
✗ Branch 187 not taken.
✓ Branch 188 taken 403 times.
✗ Branch 189 not taken.
✓ Branch 190 taken 403 times.
✗ Branch 191 not taken.
✓ Branch 192 taken 403 times.
✗ Branch 193 not taken.
✓ Branch 194 taken 403 times.
✗ Branch 195 not taken.
✓ Branch 196 taken 403 times.
✗ Branch 197 not taken.
✓ Branch 198 taken 403 times.
✗ Branch 199 not taken.
✓ Branch 200 taken 403 times.
✗ Branch 201 not taken.
✓ Branch 202 taken 403 times.
✗ Branch 203 not taken.
✓ Branch 204 taken 403 times.
✗ Branch 205 not taken.
✓ Branch 206 taken 403 times.
✗ Branch 207 not taken.
✓ Branch 208 taken 403 times.
✗ Branch 209 not taken.
✓ Branch 210 taken 403 times.
✗ Branch 211 not taken.
✓ Branch 212 taken 403 times.
✗ Branch 213 not taken.
✓ Branch 214 taken 403 times.
✗ Branch 215 not taken.
✓ Branch 216 taken 403 times.
✗ Branch 217 not taken.
✓ Branch 218 taken 403 times.
✗ Branch 219 not taken.
✓ Branch 220 taken 403 times.
✗ Branch 221 not taken.
✓ Branch 222 taken 403 times.
✗ Branch 223 not taken.
✓ Branch 224 taken 403 times.
✗ Branch 225 not taken.
✓ Branch 226 taken 403 times.
✗ Branch 227 not taken.
✓ Branch 228 taken 403 times.
✗ Branch 229 not taken.
✓ Branch 230 taken 403 times.
✗ Branch 231 not taken.
✓ Branch 232 taken 403 times.
✗ Branch 233 not taken.
✓ Branch 234 taken 403 times.
✗ Branch 235 not taken.
✓ Branch 236 taken 403 times.
✗ Branch 237 not taken.
✓ Branch 238 taken 403 times.
✗ Branch 239 not taken.
✓ Branch 240 taken 403 times.
✗ Branch 241 not taken.
✓ Branch 242 taken 403 times.
✗ Branch 243 not taken.
✓ Branch 244 taken 403 times.
✗ Branch 245 not taken.
✓ Branch 246 taken 403 times.
✗ Branch 247 not taken.
✓ Branch 248 taken 403 times.
✗ Branch 249 not taken.
✓ Branch 250 taken 403 times.
✗ Branch 251 not taken.
✓ Branch 252 taken 403 times.
✗ Branch 253 not taken.
✓ Branch 254 taken 403 times.
✗ Branch 255 not taken.
✓ Branch 256 taken 403 times.
✗ Branch 257 not taken.
✓ Branch 258 taken 403 times.
✗ Branch 259 not taken.
✓ Branch 260 taken 403 times.
✗ Branch 261 not taken.
✓ Branch 262 taken 403 times.
✗ Branch 263 not taken.
✓ Branch 264 taken 403 times.
✗ Branch 265 not taken.
✓ Branch 266 taken 403 times.
✗ Branch 267 not taken.
✓ Branch 268 taken 403 times.
✗ Branch 269 not taken.
✓ Branch 270 taken 403 times.
✗ Branch 271 not taken.
✓ Branch 272 taken 403 times.
✗ Branch 273 not taken.
✓ Branch 274 taken 403 times.
✗ Branch 275 not taken.
✓ Branch 276 taken 403 times.
✗ Branch 277 not taken.
✓ Branch 278 taken 403 times.
✗ Branch 279 not taken.
✓ Branch 280 taken 403 times.
✗ Branch 281 not taken.
✓ Branch 282 taken 403 times.
✗ Branch 283 not taken.
✓ Branch 284 taken 403 times.
✗ Branch 285 not taken.
✓ Branch 286 taken 403 times.
✗ Branch 287 not taken.
✓ Branch 288 taken 403 times.
✗ Branch 289 not taken.
✓ Branch 290 taken 403 times.
✗ Branch 291 not taken.
✓ Branch 292 taken 403 times.
✗ Branch 293 not taken.
✓ Branch 294 taken 403 times.
✗ Branch 295 not taken.
✓ Branch 296 taken 403 times.
✗ Branch 297 not taken.
✓ Branch 298 taken 403 times.
✗ Branch 299 not taken.
✓ Branch 300 taken 403 times.
✗ Branch 301 not taken.
✓ Branch 302 taken 403 times.
✗ Branch 303 not taken.
✓ Branch 304 taken 403 times.
✗ Branch 305 not taken.
✓ Branch 306 taken 403 times.
✗ Branch 307 not taken.
✓ Branch 308 taken 403 times.
✗ Branch 309 not taken.
✓ Branch 310 taken 403 times.
✗ Branch 311 not taken.
✓ Branch 312 taken 403 times.
✗ Branch 313 not taken.
✓ Branch 314 taken 403 times.
✗ Branch 315 not taken.
✓ Branch 316 taken 403 times.
✗ Branch 317 not taken.
✓ Branch 318 taken 403 times.
✗ Branch 319 not taken.
✓ Branch 320 taken 403 times.
✗ Branch 321 not taken.
✓ Branch 322 taken 403 times.
✗ Branch 323 not taken.
✓ Branch 324 taken 403 times.
✗ Branch 325 not taken.
✓ Branch 326 taken 403 times.
✗ Branch 327 not taken.
✓ Branch 328 taken 403 times.
✗ Branch 329 not taken.
✓ Branch 330 taken 403 times.
✗ Branch 331 not taken.
✓ Branch 332 taken 403 times.
✗ Branch 333 not taken.
✓ Branch 334 taken 403 times.
✗ Branch 335 not taken.
✓ Branch 336 taken 403 times.
✗ Branch 337 not taken.
✓ Branch 338 taken 403 times.
✗ Branch 339 not taken.
✓ Branch 340 taken 403 times.
✗ Branch 341 not taken.
✓ Branch 342 taken 403 times.
✗ Branch 343 not taken.
✓ Branch 344 taken 403 times.
✗ Branch 345 not taken.
✓ Branch 346 taken 403 times.
✗ Branch 347 not taken.
✓ Branch 348 taken 403 times.
✗ Branch 349 not taken.
✓ Branch 350 taken 403 times.
✗ Branch 351 not taken.
✓ Branch 352 taken 403 times.
✗ Branch 353 not taken.
✓ Branch 354 taken 403 times.
✗ Branch 355 not taken.
✓ Branch 356 taken 403 times.
✗ Branch 357 not taken.
✓ Branch 358 taken 403 times.
✗ Branch 359 not taken.
✓ Branch 360 taken 403 times.
✗ Branch 361 not taken.
✓ Branch 362 taken 403 times.
✗ Branch 363 not taken.
✓ Branch 364 taken 403 times.
✗ Branch 365 not taken.
✓ Branch 366 taken 403 times.
✗ Branch 367 not taken.
✓ Branch 368 taken 403 times.
✗ Branch 369 not taken.
✓ Branch 370 taken 403 times.
✗ Branch 371 not taken.
✓ Branch 372 taken 403 times.
✗ Branch 373 not taken.
✗ Branch 374 not taken.
✗ Branch 375 not taken.
403 static std::set<std::string> banned_extensions = {".xlm",".caction",".8ck", ".actc",".a6p", ".m3g",".run",".workflow",".otm",".apk",".fxp",".73k",".0xe",".exe",".cmd",".jsx",".scar",".wcm",".jar",".ebs2",".ipa",".xap",".ba_",".ac",".bin",".vlx",".icd",".elf",".xbap",".89k",".widget",".a7r",".ex_",".zl9",".cgi",".scr",".coffee",".ahk",".plsc",".air",".ear",".app",".scptd",".xys",".hms",".cyw",".ebm",".pwc",".xqt",".msl",".seed",".vexe",".ebs",".mcr",".gpu",".celx",".wsh",".frs",".vxp",".action",".com",".out",".gadget",".command",".script",".rfu",".tcp",".widget",".ex4",".bat",".cof",".phar",".rxe",".scb",".ms",".isu",".fas",".mlx",".gpe",".mcr",".mrp",".u3p",".js",".acr",".epk",".exe1",".jsf",".rbf",".rgs",".vpm",".ecf",".hta",".dld",".applescript",".prg",".pyc",".spr",".nexe",".server",".appimage",".pyo",".dek",".mrc",".fpi",".rpj",".iim",".vbs",".pif",".mel",".scpt",".csh",".paf",".ws",".mm",".acc",".ex5",".mac",".plx",".snap",".ps1",".vdo",".mxe",".gs",".osx",".sct",".wiz",".x86",".e_e",".fky",".prg",".fas",".azw2",".actm",".cel",".tiapp",".thm",".kix",".wsf",".vbe",".lo",".ls",".tms",".ezs",".ds",".n",".esh",".vbscript",".arscript",".qit",".pex",".dxl",".wpm",".s2a",".sca",".prc",".shb",".rbx",".jse",".beam",".udf",".mem",".kx",".ksh",".rox",".upx",".ms",".mam",".btm",".es",".asb",".ipf",".mio",".sbs",".hpf",".ita",".eham",".ezt",".dmc",".qpx",".ore",".ncl",".exopc",".smm",".pvd",".ham",".wpk"};
34757
34758 // If the path is valid, returns an absolute path under the quest "Files" directory.
34759 2 static expected<std::string, std::string> parse_user_path(const std::string& user_path, bool is_file)
34760 {
34761 // First check for non-portable path characters.
34762 static const char* invalid_chars = "<>|?*&^$#\":";
34763
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (auto index = user_path.find_first_of(invalid_chars) != string::npos)
34764 {
34765 return make_unexpected(fmt::format("Bad path: {} - invalid character {}", user_path, user_path[index]));
34766 }
34767
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 2 times.
56 for (char c : user_path)
34768 {
34769
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if (c < 32)
34770 return make_unexpected(fmt::format("Bad path: {} - invalid control character {:#x}", user_path, c));
34771 }
34772
34773 // Any leading slashes are ignored.
34774 // This makes path always relative.
34775 2 const char* path = user_path.c_str();
34776
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 while (path[0] == '/' || path[0] == '\\')
34777 path++;
34778
34779 // Normalize `user_path` and check if it accesses a parent path.
34780
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 auto files_path = fs::absolute(fs::path(qst_files_path));
34781
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 auto normalized_path = fs::path(path).lexically_normal();
34782
5/12
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
4 if (!normalized_path.empty() && normalized_path.begin()->string() == "..")
34783 {
34784 return make_unexpected(fmt::format("Bad path: {} (resolved to {}) - cannot access filesystem outside {} (too many ..?)",
34785 path, normalized_path.string(), files_path.string()));
34786 }
34787
34788
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 auto resolved_path = files_path / normalized_path;
34789
34790 // The above should be enough to guarantee that `resolved_path` is within
34791 // the quest "Files" folder, but check to be safe.
34792
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 auto mismatch_pair = std::mismatch(
34793 2 resolved_path.begin(), resolved_path.end(),
34794 2 files_path.begin(), files_path.end());
34795 2 bool is_subpath = mismatch_pair.second == files_path.end();
34796
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!is_subpath)
34797 {
34798 return make_unexpected(fmt::format("Bad path: {} (resolved to {}) - cannot access filesystem outside {}",
34799 user_path, resolved_path.string(), files_path.string()));
34800 }
34801
34802 // Any extension other than banned ones, including no extension, is allowed.
34803
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 if (is_file && resolved_path.has_extension())
34804 {
34805
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 auto ext = resolved_path.extension().string();
34806
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (banned_extensions.find(ext) != banned_extensions.end())
34807 return make_unexpected(fmt::format("Bad path: {} - banned extension", user_path));
34808
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 }
34809
34810
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (is_file && !resolved_path.has_filename())
34811 return make_unexpected(fmt::format("Bad path: {} - missing filename", user_path));
34812
34813 // https://stackoverflow.com/a/31976060/2788187
34814
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (is_file)
34815 {
34816 static auto banned_fnames = {
34817 "..", ".", "AUX", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6",
34818 "COM7", "COM8", "COM9", "CON", "LPT1", "LPT2", "LPT3", "LPT4",
34819 "LPT5", "LPT6", "LPT7", "LPT8", "LPT9", "NUL", "PRN",
34820 };
34821
34822
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 auto stem = resolved_path.stem().string();
34823
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 auto fname = resolved_path.filename().string();
34824
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 bool banned = std::find(std::begin(banned_fnames), std::end(banned_fnames), stem) != std::end(banned_fnames);
34825
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 banned |= fname.ends_with(".") || fname.ends_with(" ");
34826
34827
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (banned)
34828 return make_unexpected(fmt::format("Bad path: {} - banned filename", user_path));
34829
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 }
34830
34831
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 return resolved_path.string();
34832 2 }
34833
34834 bool FFScript::get_scriptfile_path(char* buf, const char* path)
34835 {
34836 while((path[0] == '/' || path[0] == '\\') && path[0]) ++path;
34837 if(path[0])
34838 sprintf(buf, "%s%c%s", qst_files_path, PATH_SLASH, path);
34839 else sprintf(buf, "%s", qst_files_path);
34840 return true;
34841 }
34842
34843 280 void check_file_error(int32_t ref)
34844 {
34845
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 280 times.
280 if(user_file* f = checkFile(ref, true, true))
34846 {
34847 280 int32_t err = ferror(f->file);
34848
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 280 times.
280 if(err != 0)
34849 {
34850 Z_scripterrlog("File with UID '%ld' encountered an error.\n", ref);
34851 Z_scripterrlog("File error: %s\n", strerror(err));
34852 }
34853 280 }
34854 280 }
34855
34856 2 void FFScript::do_fopen(const bool v, const char* f_mode)
34857 {
34858 2 int32_t arrayptr = SH::get_arg(sarg1, v) / 10000;
34859 2 string user_path;
34860
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 ArrayH::getString(arrayptr, user_path, 512);
34861
34862 2 ri->d[rEXP1] = 0L; //Presume failure; update to 10000L on success
34863 2 ri->d[rEXP2] = 0;
34864
34865 2 std::string resolved_path;
34866
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 if (auto r = parse_user_path(user_path, true); !r)
34867 {
34868 scripting_log_error_with_context("Error: {}", r.error());
34869 return;
34870
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 } else resolved_path = r.value();
34871
34872
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 user_file* f = checkFile(ri->fileref, false, true);
34873
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!f) //auto-allocate
34874 {
34875
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 ri->fileref = user_files.get_free();
34876
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 f = checkFile(ri->fileref, false, true);
34877 2 }
34878 2 ri->d[rEXP2] = ri->fileref; //Returns to the variable!
34879
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(f)
34880 {
34881
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 f->close(); //Close the old FILE* before overwriting it!
34882 2 bool create = false;
34883
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
5 for(int32_t q = 0; f_mode[q]; ++q)
34884 {
34885
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
4 if(f_mode[q] == 'w' || f_mode[q] == 'a')
34886 {
34887 1 create = true;
34888 1 break;
34889 }
34890 3 }
34891
4/6
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
2 if(!create || make_dirs_for_file(resolved_path))
34892 {
34893
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 f->file = fopen(resolved_path.c_str(), f_mode);
34894
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 fflush(f->file);
34895
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 zc_chmod(resolved_path.c_str(), SCRIPT_FILE_MODE);
34896
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 f->setPath(resolved_path.c_str());
34897 //r+; read-write, will not create if does not exist, will not delete content if does exist.
34898 //w+; read-write, will create if does not exist, will delete all content if does exist.
34899
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if(f->file)
34900 {
34901 1 ri->d[rEXP1] = 10000L; //Success
34902 1 return;
34903 }
34904 1 }
34905 else
34906 {
34907 Z_scripterrlog("Script failed to create directories for file path '%s'.\n", resolved_path.c_str());
34908 ri->d[rEXP2] = 0;
34909 return;
34910 }
34911 1 }
34912
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 }
34913
34914 void FFScript::do_fremove()
34915 {
34916 if(user_file* f = checkFile(ri->fileref, true))
34917 {
34918 zprint2("Removing file %d\n", ri->fileref);
34919 ri->d[rEXP1] = f->do_remove() ? 0L : 10000L;
34920 }
34921 else ri->d[rEXP1] = 0L;
34922 }
34923
34924 void FFScript::do_fclose()
34925 {
34926 if(user_file* f = checkFile(ri->fileref, false, true))
34927 {
34928 f->close();
34929 }
34930 //No else. If invalid, no error is thrown.
34931 }
34932
34933 void FFScript::do_allocate_file()
34934 {
34935 //Get a file and return it
34936 ri->fileref = user_files.get_free();
34937 ri->d[rEXP2] = ri->fileref; //Return to ptr
34938 ri->d[rEXP1] = (ri->d[rEXP2] == 0 ? 0L : 10000L);
34939 }
34940
34941 1 void FFScript::do_deallocate_file()
34942 {
34943 1 user_file* f = checkFile(ri->fileref, false, true);
34944
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(f) free_script_object(f->id);
34945 1 }
34946
34947 void FFScript::do_file_isallocated() //Returns true if file is allocated
34948 {
34949 user_file* f = checkFile(ri->fileref, false, true);
34950 ri->d[rEXP1] = (f) ? 10000L : 0L;
34951 }
34952
34953 void FFScript::do_file_isvalid() //Returns true if file is allocated and has an open FILE*
34954 {
34955 user_file* f = checkFile(ri->fileref, true, true);
34956 ri->d[rEXP1] = (f) ? 10000L : 0L;
34957 }
34958
34959 1 void FFScript::do_fflush()
34960 {
34961 1 ri->d[rEXP1] = 0L;
34962
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(user_file* f = checkFile(ri->fileref, true))
34963 {
34964
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!fflush(f->file))
34965 1 ri->d[rEXP1] = 10000L;
34966 1 check_file_error(ri->fileref);
34967 1 }
34968 1 }
34969
34970 void FFScript::do_file_readchars()
34971 {
34972 if(user_file* f = checkFile(ri->fileref, true))
34973 {
34974 uint32_t pos = zc_max(ri->d[rINDEX] / 10000,0);
34975 int32_t count = get_register(sarg2) / 10000;
34976 if(count == 0) return;
34977 int32_t arrayptr = get_register(sarg1) / 10000;
34978 ArrayManager am(arrayptr);
34979 int32_t sz = am.size();
34980 if(sz <= 0)
34981 return;
34982 if(pos >= sz)
34983 {
34984 Z_scripterrlog("Pos (%d) passed to %s is outside the bounds of array %d. Aborting.\n", pos, "ReadChars()", arrayptr);
34985 return;
34986 }
34987 if(count < 0 || unsigned(count) > sz-pos) count = sz-pos;
34988 int32_t limit = pos+count;
34989 char c;
34990 word q;
34991 ri->d[rEXP1] = 0;
34992 for(q = pos; q < limit; ++q)
34993 {
34994 c = fgetc(f->file);
34995 if(feof(f->file) || ferror(f->file))
34996 break;
34997 if(c <= 0)
34998 break;
34999 am.set(q,c * 10000L);
35000 ++ri->d[rEXP1]; //Don't count nullchar towards length
35001 }
35002 if(q >= limit)
35003 {
35004 --q;
35005 --ri->d[rEXP1];
35006 ungetc(am.get(q), f->file); //Put the character back before overwriting it
35007 }
35008 am.set(q,0); //Force null-termination
35009 ri->d[rEXP1] *= 10000L;
35010 check_file_error(ri->fileref);
35011 return;
35012 }
35013 ri->d[rEXP1] = 0L;
35014 }
35015 void FFScript::do_file_readbytes()
35016 {
35017 if(user_file* f = checkFile(ri->fileref, true))
35018 {
35019 uint32_t pos = zc_max(ri->d[rINDEX] / 10000,0);
35020 int32_t count = get_register(sarg2) / 10000;
35021 if(count == 0) return;
35022 int32_t arrayptr = get_register(sarg1) / 10000;
35023 ArrayManager am(arrayptr);
35024 int32_t sz = am.size();
35025 if(sz <= 0)
35026 return;
35027 if(pos >= sz)
35028 {
35029 Z_scripterrlog("Pos (%d) passed to %s is outside the bounds of array %d. Aborting.\n", pos, "ReadBytes()", arrayptr);
35030 return;
35031 }
35032 if(count < 0 || unsigned(count) > sz-pos) count = sz-pos;
35033 std::vector<uint8_t> data(count);
35034 ri->d[rEXP1] = 10000L * fread((void*)&(data[0]), 1, count, f->file);
35035 for(int32_t q = 0; q < count; ++q)
35036 {
35037 am.set(q+pos, 10000L * data[q]);
35038 }
35039 check_file_error(ri->fileref);
35040 return;
35041 }
35042 ri->d[rEXP1] = 0L;
35043 }
35044 void FFScript::do_file_readstring()
35045 {
35046 if(user_file* f = checkFile(ri->fileref, true))
35047 {
35048 int32_t arrayptr = get_register(sarg1) / 10000;
35049 ArrayManager am(arrayptr);
35050 int32_t sz = am.size();
35051 if(sz <= 0)
35052 return;
35053 int32_t limit = sz;
35054 int32_t c;
35055 word q;
35056 ri->d[rEXP1] = 0;
35057 for(q = 0; q < limit; ++q)
35058 {
35059 c = fgetc(f->file);
35060 if(feof(f->file) || ferror(f->file))
35061 break;
35062 if(c <= 0)
35063 break;
35064 am.set(q,c * 10000L);
35065 ++ri->d[rEXP1]; //Don't count nullchar towards length
35066 if(c == '\n')
35067 {
35068 ++q;
35069 break;
35070 }
35071 }
35072 if(q >= limit)
35073 {
35074 --q;
35075 --ri->d[rEXP1];
35076 ungetc(am.get(q), f->file); //Put the character back before overwriting it
35077 }
35078 am.set(q,0); //Force null-termination
35079 ri->d[rEXP1] *= 10000L;
35080 check_file_error(ri->fileref);
35081 return;
35082 }
35083 ri->d[rEXP1] = 0L;
35084 }
35085 void FFScript::do_file_readints()
35086 {
35087 if(user_file* f = checkFile(ri->fileref, true))
35088 {
35089 uint32_t pos = zc_max(ri->d[rINDEX] / 10000,0);
35090 int32_t count = get_register(sarg2) / 10000;
35091 if(count == 0) return;
35092 int32_t arrayptr = get_register(sarg1) / 10000;
35093 ArrayManager am(arrayptr);
35094 int32_t sz = am.size();
35095 if(sz <= 0)
35096 return;
35097 if(pos >= sz)
35098 {
35099 Z_scripterrlog("Pos (%d) passed to %s is outside the bounds of array %d. Aborting.\n", pos, "ReadInts()", arrayptr);
35100 return;
35101 }
35102 if(count < 0 || unsigned(count) > sz-pos) count = sz-pos;
35103
35104 std::vector<int32_t> data(count);
35105 ri->d[rEXP1] = 10000L * fread((void*)&(data[0]), 4, count, f->file);
35106 for(int32_t q = 0; q < count; ++q)
35107 {
35108 am.set(q+pos,data[q]);
35109 }
35110 check_file_error(ri->fileref);
35111 return;
35112 }
35113 ri->d[rEXP1] = 0L;
35114 }
35115 void FFScript::do_file_writechars()
35116 {
35117 if(user_file* f = checkFile(ri->fileref, true))
35118 {
35119 int32_t pos = zc_max(ri->d[rINDEX] / 10000,0);
35120 int32_t count = get_register(sarg2) / 10000;
35121 if(count == 0) return;
35122 if(count == -1 || count > (MAX_ZC_ARRAY_SIZE-pos)) count = MAX_ZC_ARRAY_SIZE-pos;
35123 int32_t arrayptr = get_register(sarg1) / 10000;
35124 string output;
35125 ArrayH::getString(arrayptr, output, count, pos);
35126 uint32_t q = 0;
35127 for(; q < output.length(); ++q)
35128 {
35129 if(fputc(output[q], f->file)<0)
35130 break;
35131 }
35132 ri->d[rEXP1] = q * 10000L;
35133 check_file_error(ri->fileref);
35134 return;
35135 }
35136 ri->d[rEXP1] = 0L;
35137 }
35138
35139 void FFScript::do_file_writebytes()
35140 {
35141 if(user_file* f = checkFile(ri->fileref, true))
35142 {
35143 uint32_t pos = zc_max(ri->d[rINDEX] / 10000,0);
35144 int32_t arg = get_register(sarg2) / 10000;
35145 if(arg == 0) return;
35146 uint32_t count = ((arg<0 || unsigned(arg) >(MAX_ZC_ARRAY_SIZE - pos)) ? MAX_ZC_ARRAY_SIZE - pos : unsigned(arg));
35147 int32_t arrayptr = get_register(sarg1) / 10000;
35148 string output;
35149 ArrayManager am(arrayptr);
35150 if(am.invalid()) return;
35151 int32_t sz = am.size();
35152 if(sz <= 0)
35153 return;
35154 if(pos >= sz)
35155 {
35156 Z_scripterrlog("Pos (%d) passed to %s is outside the bounds of array %d. Aborting.\n", pos, "WriteBytes()", arrayptr);
35157 return;
35158 }
35159 if (count > sz-pos) count = sz-pos;
35160 std::vector<uint8_t> data(count);
35161 for(uint32_t q = 0; q < count; ++q)
35162 {
35163 data[q] = am.get(q+pos) / 10000;
35164 }
35165 ri->d[rEXP1] = 10000L * fwrite((const void*)&(data[0]), 1, count, f->file);
35166 check_file_error(ri->fileref);
35167 return;
35168 }
35169 ri->d[rEXP1] = 0L;
35170 }
35171 279 void FFScript::do_file_writestring()
35172 {
35173
1/2
✓ Branch 0 taken 279 times.
✗ Branch 1 not taken.
279 if(user_file* f = checkFile(ri->fileref, true))
35174 {
35175 279 int32_t arrayptr = get_register(sarg1) / 10000;
35176 279 string output;
35177
1/2
✓ Branch 0 taken 279 times.
✗ Branch 1 not taken.
279 ArrayH::getString(arrayptr, output, ZSCRIPT_MAX_STRING_CHARS);
35178 279 uint32_t q = 0;
35179
2/2
✓ Branch 0 taken 12719 times.
✓ Branch 1 taken 279 times.
12998 for(; q < output.length(); ++q)
35180 {
35181
3/6
✓ Branch 0 taken 12719 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12719 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12719 times.
✗ Branch 5 not taken.
12719 if(fputc(output[q], f->file)<0)
35182 break;
35183 12719 }
35184 279 ri->d[rEXP1] = q * 10000L;
35185
1/2
✓ Branch 0 taken 279 times.
✗ Branch 1 not taken.
279 check_file_error(ri->fileref);
35186 return;
35187 279 }
35188 ri->d[rEXP1] = 0L;
35189 279 }
35190 void FFScript::do_file_writeints()
35191 {
35192 if(user_file* f = checkFile(ri->fileref, true))
35193 {
35194 uint32_t pos = zc_max(ri->d[rINDEX] / 10000,0);
35195 int32_t count = get_register(sarg2) / 10000;
35196 if(count == 0) return;
35197 int32_t arrayptr = get_register(sarg1) / 10000;
35198 ArrayManager am(arrayptr);
35199 if(am.invalid()) return;
35200 int32_t sz = am.size();
35201 if(sz <= 0)
35202 return;
35203 if(pos >= sz)
35204 {
35205 Z_scripterrlog("Pos (%d) passed to %s is outside the bounds of array %d. Aborting.\n", pos, "WriteInts()", arrayptr);
35206 return;
35207 }
35208
35209 if(count < 0 || unsigned(count) > sz-pos) count = sz-pos;
35210 std::vector<int32_t> data(count);
35211 for(int32_t q = 0; q < count; ++q)
35212 {
35213 data[q] = am.get(q+pos);
35214 }
35215 ri->d[rEXP1] = 10000L * fwrite((const void*)&(data[0]), 4, count, f->file);
35216 check_file_error(ri->fileref);
35217 return;
35218 }
35219 ri->d[rEXP1] = 0L;
35220 }
35221
35222 void FFScript::do_file_getchar()
35223 {
35224 if(user_file* f = checkFile(ri->fileref, true))
35225 {
35226 ri->d[rEXP1] = fgetc(f->file) * 10000L;
35227 check_file_error(ri->fileref);
35228 return;
35229 }
35230 ri->d[rEXP1] = -10000L; //-1 == EOF; error value
35231 }
35232 void FFScript::do_file_putchar()
35233 {
35234 if(user_file* f = checkFile(ri->fileref, true))
35235 {
35236 int32_t c = get_register(sarg1) / 10000;
35237 if(char(c) != c)
35238 {
35239 Z_scripterrlog("Invalid character val %d passed to PutChar(); value will overflow.", c);
35240 c = char(c);
35241 }
35242 ri->d[rEXP1] = fputc(c, f->file) * 10000L;
35243 check_file_error(ri->fileref);
35244 return;
35245 }
35246 ri->d[rEXP1] = -10000L; //-1 == EOF; error value
35247 }
35248 void FFScript::do_file_ungetchar()
35249 {
35250 if(user_file* f = checkFile(ri->fileref, true))
35251 {
35252 int32_t c = get_register(sarg1) / 10000;
35253 if(char(c) != c)
35254 {
35255 Z_scripterrlog("Invalid character val %d passed to UngetChar(); value will overflow.", c);
35256 c = char(c);
35257 }
35258 ri->d[rEXP1] = ungetc(c,f->file) * 10000L;
35259 check_file_error(ri->fileref);
35260 return;
35261 }
35262 ri->d[rEXP1] = -10000L; //-1 == EOF; error value
35263 }
35264
35265 void FFScript::do_file_seek()
35266 {
35267 if(user_file* f = checkFile(ri->fileref, true))
35268 {
35269 int32_t pos = get_register(sarg1); //NOT /10000 -V
35270 int32_t origin = get_register(sarg2) ? SEEK_CUR : SEEK_SET;
35271 ri->d[rEXP1] = fseek(f->file, pos, origin) ? 0L : 10000L;
35272 check_file_error(ri->fileref);
35273 return;
35274 }
35275 ri->d[rEXP1] = 0;
35276 }
35277 void FFScript::do_file_rewind()
35278 {
35279 if(user_file* f = checkFile(ri->fileref, true))
35280 {
35281 //fseek(f->file, 0L, SEEK_END);
35282 rewind(f->file);
35283 check_file_error(ri->fileref);
35284 }
35285 }
35286 void FFScript::do_file_clearerr()
35287 {
35288 if(user_file* f = checkFile(ri->fileref, true))
35289 {
35290 clearerr(f->file);
35291 }
35292 }
35293
35294 void FFScript::do_file_geterr()
35295 {
35296 if(user_file* f = checkFile(ri->fileref, true))
35297 {
35298 int32_t err = ferror(f->file);
35299 int32_t arrayptr = get_register(sarg1) / 10000;
35300 if(err)
35301 {
35302 string error = strerror(err);
35303 ArrayH::setArray(arrayptr, error);
35304 }
35305 else
35306 {
35307 ArrayH::setArray(arrayptr, "\0");
35308 }
35309 }
35310 }
35311 ///----------------------------------------------------------------------------------------------------
35312 //Directory
35313
35314 void FFScript::do_directory_get()
35315 {
35316 if(user_dir* dr = checkDir(ri->directoryref, true))
35317 {
35318 int32_t indx = get_register(sarg1) / 10000L;
35319 int32_t arrayptr = get_register(sarg2) / 10000L;
35320 char buf[2048] = {0};
35321 set_register(sarg1, dr->get(indx, buf) ? 10000L : 0L);
35322 if(ArrayH::setArray(arrayptr, string(buf)) == SH::_Overflow)
35323 scripting_log_error_with_context("Array is not large enough");
35324 }
35325 else set_register(sarg1, 0L);
35326 }
35327
35328 void FFScript::do_directory_reload()
35329 {
35330 if(user_dir* dr = checkDir(ri->directoryref, true))
35331 {
35332 dr->refresh();
35333 }
35334 }
35335
35336 void FFScript::do_directory_free()
35337 {
35338 if(user_dir* dr = checkDir(ri->directoryref, true))
35339 {
35340 free_script_object(dr->id);
35341 }
35342 }
35343
35344 ///----------------------------------------------------------------------------------------------------
35345
35346 void FFScript::set_sarg1(int32_t v)
35347 {
35348 set_register(sarg1, v);
35349 }
35350
35351 5 void FFScript::do_isvalidbitmap()
35352 {
35353 5 int32_t id = get_register(sarg1);
35354
35355
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (id >= 0)
35356 {
35357 5 auto bmp = user_bitmaps.check(id, true);
35358
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
5 if (bmp && bmp->u_bmp)
35359 {
35360 set_register(sarg1, 10000);
35361 return;
35362 }
35363 5 }
35364
35365 5 set_register(sarg1, 0);
35366 5 }
35367 43 void FFScript::do_isallocatedbitmap()
35368 {
35369 43 int32_t id = get_register(sarg1);
35370
35371
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 if (id >= 0)
35372 {
35373 43 auto bmp = user_bitmaps.check(id, true);
35374
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 42 times.
43 if (bmp)
35375 {
35376 42 set_register(sarg1, 10000);
35377 42 return;
35378 }
35379 1 }
35380
35381 1 set_register(sarg1, 0);
35382 43 }
35383
35384 784 void FFScript::user_bitmaps_init()
35385 {
35386 784 user_bitmaps.clear();
35387 784 }
35388
35389 3856 int32_t FFScript::do_create_bitmap()
35390 {
35391 3856 int32_t w = (ri->d[rINDEX2] / 10000);
35392 3856 int32_t h = (ri->d[rINDEX]/10000);
35393
1/2
✓ Branch 0 taken 3856 times.
✗ Branch 1 not taken.
3856 if ( get_qr(qr_OLDCREATEBITMAP_ARGS) )
35394 {
35395 std::swap(w, h);
35396 }
35397
35398 3856 return create_user_bitmap_ex(h,w);
35399 }
35400
35401 3856 uint32_t FFScript::create_user_bitmap_ex(int32_t w, int32_t h)
35402 {
35403 3856 auto bmp = user_bitmaps.create();
35404
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3856 times.
3856 if (!bmp)
35405 return 0;
35406
35407 3856 bmp->width = w;
35408 3856 bmp->height = h;
35409 3856 bmp->u_bmp = create_bitmap_ex(8,w,h);
35410 3856 clear_bitmap(bmp->u_bmp);
35411 3856 return bmp->id;
35412 3856 }
35413
35414 1800 bool FFScript::doesResolveToScreenBitmap(int32_t bitmap_id)
35415 {
35416
2/2
✓ Branch 0 taken 1440 times.
✓ Branch 1 taken 360 times.
1800 if (bitmap_id == rtSCREEN)
35417 360 return true;
35418
35419
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1440 times.
1440 if (bitmap_id == -2)
35420 {
35421 int curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
35422 if (curr_rt >= 0 && curr_rt < 7)
35423 return false;
35424
35425 return true;
35426 }
35427
35428 1440 return false;
35429 1800 }
35430
35431 1800 bool FFScript::doesResolveToDeprecatedSystemBitmap(int32_t bitmap_id)
35432 {
35433
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1800 times.
1800 switch (bitmap_id)
35434 {
35435 case rtBMP0:
35436 case rtBMP1:
35437 case rtBMP2:
35438 case rtBMP3:
35439 case rtBMP4:
35440 case rtBMP5:
35441 case rtBMP6:
35442 {
35443 return true;
35444 }
35445 }
35446
35447
1/2
✓ Branch 0 taken 1800 times.
✗ Branch 1 not taken.
1800 if (bitmap_id == -2)
35448 {
35449 int curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
35450 if (curr_rt >= 0 && curr_rt < 7)
35451 return true;
35452 }
35453
35454 1800 return false;
35455 1800 }
35456
35457 53366459 BITMAP* FFScript::GetScriptBitmap(int32_t id, bool skipError)
35458 {
35459
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53366459 times.
53366459 switch (id - 10)
35460 {
35461 case rtSCREEN:
35462 case rtBMP0:
35463 case rtBMP1:
35464 case rtBMP2:
35465 case rtBMP3:
35466 case rtBMP4:
35467 case rtBMP5:
35468 case rtBMP6: //old system bitmaps (render targets)
35469 {
35470 return zscriptDrawingRenderTarget->GetBitmapPtr(id);
35471 }
35472 }
35473
35474
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53366459 times.
53366459 if (auto bitmap = checkBitmap(id, true, skipError))
35475 53366459 return bitmap->u_bmp;
35476
35477 return nullptr;
35478 53366459 }
35479
35480 225 uint32_t FFScript::get_free_bitmap(bool skipError)
35481 {
35482 225 auto bmp = user_bitmaps.create(skipError);
35483
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 225 times.
225 if (!bmp)
35484 return 0;
35485 225 return bmp->id;
35486 225 }
35487
35488 3512 void FFScript::do_deallocate_bitmap()
35489 {
35490
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3512 times.
3512 if (ZScriptVersion::gc())
35491 return;
35492
35493
1/2
✓ Branch 0 taken 3512 times.
✗ Branch 1 not taken.
3512 if(isSystemBitref(ri->bitmapref))
35494 {
35495 return; //Don't attempt to deallocate system bitmaps!
35496 }
35497
35498 // Bitmaps are not deallocated right away, but deferred until the next call to scb.update()
35499
1/2
✓ Branch 0 taken 3512 times.
✗ Branch 1 not taken.
3512 if (auto b = checkBitmap(ri->bitmapref, false, true))
35500 3512 b->free_obj();
35501 3512 }
35502
35503 3658 bool FFScript::isSystemBitref(int32_t ref)
35504 {
35505
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 switch(ref-10)
35506 {
35507 case rtSCREEN:
35508 case rtBMP0:
35509 case rtBMP1:
35510 case rtBMP2:
35511 case rtBMP3:
35512 case rtBMP4:
35513 case rtBMP5:
35514 case rtBMP6:
35515 return true;
35516 }
35517 3658 return false;
35518 3658 }
35519
35520 ///----------------------------------------------------------------------------------------------------
35521
35522 1661 int32_t FFScript::GetQuestVersion()
35523 {
35524 1661 return QHeader.zelda_version;
35525 }
35526 729 int32_t FFScript::GetQuestBuild()
35527 {
35528 729 return QHeader.build;
35529 }
35530 int32_t FFScript::GetQuestSectionVersion(int32_t section)
35531 {
35532 return QHeader.zelda_version;
35533 }
35534
35535 19 int32_t FFScript::GetDefaultWeaponSprite(int32_t wpn_id)
35536 {
35537
2/63
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✓ Branch 49 taken 10 times.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
19 switch (wpn_id)
35538 {
35539 case wNone:
35540 return 0;
35541
35542 case wSword: return 0;
35543 case wBeam: return 1;
35544 case wBrang: return 4;
35545 case wBomb: return 9;
35546 case wSBomb: return 75;
35547 case wLitBomb: return 7;
35548 case wLitSBomb: return 8;
35549 case wArrow: return 10;
35550 case wRefArrow: return 10;
35551 case wFire: return 12;
35552 case wRefFire: return 12;
35553 case wRefFire2: return 12;
35554 case wWhistle: return 45; //blank, unused misc sprite
35555 case wBait: return 14;
35556 case wWand: return 15;
35557 case wMagic: return 16;
35558 case wCatching: return 45; //blank, unused misc sprite
35559 case wWind: return 13;
35560 case wRefMagic: return 16;
35561 case wRefFireball: return 17;
35562 case wRefRock: return 18;
35563 case wHammer: return 25;
35564 case wHookshot: return 26;
35565 case wHSHandle: return 28;
35566 case wHSChain: return 27;
35567 case wSSparkle: return 29;
35568 case wFSparkle: return 32;
35569 case wSmack: return 33;
35570 case wPhantom: return -1;
35571 case wCByrna: return 87;
35572 case wRefBeam: return 1;
35573 case wStomp: return 45; //blank, unused misc sprite
35574 case lwMax: return 45; //blank, unused misc sprite
35575 case wScript1: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 246; else return 0; }
35576 case wScript2: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 247; else return 0; }
35577 case wScript3: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 248; else return 0; }
35578 case wScript4: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 249; else return 0; }
35579 case wScript5: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 250; else return 0; }
35580 case wScript6: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 251; else return 0; }
35581 case wScript7: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 252; else return 0; }
35582 case wScript8: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 253; else return 0; }
35583 case wScript9: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 254; else return 0; }
35584 case wScript10: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 255; else return 0; }
35585
35586 case wIce: return 83;
35587 //Cannot use any of these weapons yet.
35588 //return -1;
35589
35590 case wEnemyWeapons:
35591 9 case ewFireball: return 17;
35592
35593 case ewArrow: return 19;
35594 case ewBrang: return 4;
35595 10 case ewSword: return 20;
35596 case ewRock: return 18;
35597 case ewMagic: return 21;
35598 case ewBomb: return 78;
35599 case ewSBomb: return 79;
35600 case ewLitBomb: return 76;
35601 case ewLitSBomb: return 77;
35602 case ewFireTrail: return 80;
35603 case ewFlame: return 35;
35604 case ewWind: return 36;
35605 case ewFlame2: return 81;
35606 case ewFlame2Trail: return 82;
35607 case ewIce: return 83;
35608 case ewFireball2: return 17; //fireball (rising)
35609
35610
35611 default: return -1; //No assign.
35612
35613 }
35614 19 }
35615
35616 19 int32_t FFScript::GetDefaultWeaponSFX(int32_t wpn_id)
35617 {
35618
2/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
19 switch (wpn_id)
35619 {
35620 case ewFireTrail:
35621 case ewFlame:
35622 case ewFlame2Trail:
35623 case ewFlame2:
35624 return WAV_FIRE; break;
35625 case ewWind:
35626 case ewMagic:
35627 return WAV_WAND; break;
35628 case ewIce:
35629 return WAV_ZN1ICE; break;
35630 case ewRock:
35631 return WAV_ZN1ROCK; break;
35632 case ewFireball2:
35633 case ewFireball:
35634 9 return WAV_ZN1FIREBALL; break;
35635 }
35636 10 return -1; //no assign
35637 19 }
35638
35639 //bitmap->GetPixel()
35640
35641
35642 int32_t FFScript::do_getpixel()
35643 {
35644 int32_t xoffset = 0, yoffset = 0;
35645 int32_t xoff = 0; int32_t yoff = 0;
35646 const bool brokenOffset= ( (get_er(er_BITMAPOFFSET)!=0)
35647 || (get_qr(qr_BITMAPOFFSETFIX)!=0) );
35648
35649 BITMAP *bitty = FFCore.GetScriptBitmap(ri->bitmapref);
35650 if(!bitty)
35651 {
35652 bitty = scrollbuf;
35653 }
35654 // draw to screen with subscreen offset
35655 if(!brokenOffset && ri->bitmapref == rtSCREEN + 10 )
35656 {
35657 xoffset = xoff;
35658 yoffset = 56; //should this be -56?
35659 }
35660 else
35661 {
35662 xoffset = 0;
35663 yoffset = 0;
35664 }
35665
35666 int32_t yv = ri->d[rINDEX2]/10000 + yoffset;
35667 int32_t ret = getpixel(bitty, ri->d[rINDEX]/10000, yv); //This is a palette index value.
35668 if(!get_qr(qr_BROKEN_GETPIXEL_VALUE))
35669 ret *= 10000;
35670 return ret;
35671 }
35672
35673 void FFScript::do_bmpcollision()
35674 {
35675 int32_t bmpref = SH::read_stack(ri->sp + 5);
35676 int32_t maskbmpref = SH::read_stack(ri->sp + 4);
35677 int32_t x = SH::read_stack(ri->sp + 3) / 10000;
35678 int32_t y = SH::read_stack(ri->sp + 2) / 10000;
35679 int32_t checkCol = SH::read_stack(ri->sp + 1) / 10000;
35680 int32_t maskCol = SH::read_stack(ri->sp + 0) / 10000;
35681 BITMAP *checkbit = FFCore.GetScriptBitmap(bmpref, true);
35682 BITMAP *maskbit = FFCore.GetScriptBitmap(maskbmpref, true);
35683 if(!(checkbit && maskbit))
35684 {
35685 set_register(sarg1, -10000);
35686 char buf1[16];
35687 char buf2[16];
35688 zc_itoa(bmpref, buf1);
35689 zc_itoa(maskbmpref, buf2);
35690 Z_scripterrlog("Invalid bitmap%s passed to 'bitmap->CountColor()': %s%s%s\n",
35691 (checkbit || maskbit) ? "" : "s", checkbit ? "" : buf1,
35692 (checkbit || maskbit) ? "" : ", ", maskbit ? "" : buf2);
35693 return;
35694 }
35695 int32_t ret = countColor(checkbit, maskbit, x, y, checkCol, maskCol);
35696 set_register(sarg1, ret*10000);
35697 }
35698
35699
35700 6567187 int32_t FFScript::loadMapData()
35701 {
35702 6567187 int32_t map = (ri->d[rINDEX] / 10000);
35703 6567187 int32_t screen = (ri->d[rINDEX2]/10000);
35704
1/2
✓ Branch 0 taken 6567187 times.
✗ Branch 1 not taken.
6567187 int32_t indx = (zc_max((map)-1,0) * MAPSCRS + screen);
35705
2/4
✓ Branch 0 taken 6567187 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6567187 times.
6567187 if ( map < 1 || map > map_count )
35706 {
35707 Z_scripterrlog("Invalid Map ID passed to Game->LoadMapData: %d\n", map);
35708 ri->mapsref = MAX_SIGNED_32;
35709 }
35710
2/4
✓ Branch 0 taken 6567187 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6567187 times.
6567187 else if ( screen < 0 || screen > 129 ) //0x00 to 0x81 -Z
35711 {
35712 Z_scripterrlog("Invalid Screen Index passed to Game->LoadMapData: %d\n", screen);
35713 ri->mapsref = MAX_SIGNED_32;
35714 }
35715 6567187 else ri->mapsref = indx;
35716 6567187 return ri->mapsref;
35717 }
35718
35719
35720 // Called when leaving a screen; deallocate arrays created by FFCs that aren't carried over
35721 13775175 void FFScript::deallocateArray(const int32_t ptrval)
35722 {
35723
1/2
✓ Branch 0 taken 13775175 times.
✗ Branch 1 not taken.
13775175 if(ptrval == 0) return;
35724
2/4
✓ Branch 0 taken 13775175 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 13775175 times.
13775175 if(ptrval==0 || ptrval >= NUM_ZSCRIPT_ARRAYS)
35725 Z_scripterrlog("Script tried to deallocate memory at invalid address %ld\n", ptrval);
35726
1/2
✓ Branch 0 taken 13775175 times.
✗ Branch 1 not taken.
13775175 else if(ptrval<0)
35727 Z_scripterrlog("Script tried to deallocate memory at object-based address %ld\n", ptrval);
35728 else
35729 {
35730
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13775175 times.
13775175 if(arrayOwner[ptrval].specOwned) return; //ignore this deallocation
35731
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13775175 times.
13775175 if(arrayOwner[ptrval].specCleared) return;
35732 13775175 arrayOwner[ptrval].clear();
35733
35734
1/2
✓ Branch 0 taken 13775175 times.
✗ Branch 1 not taken.
13775175 if(!localRAM[ptrval].Valid())
35735 Z_scripterrlog("Script tried to deallocate memory that was not allocated at address %ld\n", ptrval);
35736 else
35737 {
35738
2/2
✓ Branch 0 taken 13775169 times.
✓ Branch 1 taken 6 times.
13775175 if (localRAM[ptrval].HoldsObjects())
35739 {
35740 6 auto&& aptr = localRAM[ptrval];
35741
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 6 times.
10 for (int i = 0; i < aptr.Size(); i++)
35742 {
35743 4 int id = aptr[i];
35744 4 script_object_ref_dec(id);
35745 4 }
35746 6 }
35747 13775175 localRAM[ptrval].Clear();
35748 }
35749 }
35750 13775175 }
35751
35752 2617631 int32_t FFScript::get_screen_d(int32_t index1, int32_t index2)
35753 {
35754
3/4
✓ Branch 0 taken 2617631 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 2617625 times.
2617631 if(index2 < 0 || index2 > 7)
35755 {
35756 6 Z_scripterrlog("You were trying to reference an out-of-bounds array index for a screen's D[] array (%ld); valid indices are from 0 to 7.\n", index1);
35757 6 return 0;
35758 }
35759
2/4
✓ Branch 0 taken 2617625 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2617625 times.
2617625 if (index1 < 0 || index1 >= game->screen_d.size())
35760 {
35761 Z_scripterrlog("You were trying to reference an out-of-bounds screen for a D[] array (%ld); valid indices are from 0 to %ld.\n", index1, game->screen_d.size() - 1);
35762 return 0;
35763 }
35764
35765 2617625 return game->screen_d[index1][index2];
35766 2617631 }
35767
35768 54370 void FFScript::set_screen_d(int32_t index1, int32_t index2, int32_t val)
35769 {
35770
2/4
✓ Branch 0 taken 54370 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 54370 times.
54370 if(index2 < 0 || index2 > 7)
35771 {
35772 Z_scripterrlog("You were trying to reference an out-of-bounds array index for a screen's D[] array (%ld); valid indices are from 0 to 7.\n", index1);
35773 return;
35774 }
35775
2/4
✓ Branch 0 taken 54370 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 54370 times.
54370 if (index1 < 0 || index1 >= game->screen_d.size())
35776 {
35777 Z_scripterrlog("You were trying to reference an out-of-bounds screen for a D[] array (%ld); valid indices are from 0 to %ld.\n", index1, game->screen_d.size() - 1);
35778 return;
35779 }
35780
35781 54370 game->screen_d[index1][index2] = val;
35782 54370 }
35783
35784 void FFScript::do_zapout()
35785 {
35786 zapout();
35787 }
35788
35789 void FFScript::do_zapin(){ zapin(); }
35790
35791 void FFScript::do_openscreen() { openscreen(); }
35792 void FFScript::do_closescreen() { closescreen(); }
35793 void FFScript::do_openscreenshape()
35794 {
35795 int32_t shape = get_register(sarg1) / 10000;
35796 if(shape < 0 || shape >= bosMAX)
35797 {
35798 Z_scripterrlog("Invalid shape passed to %s! Valid range %d to %d. Using 'Circle' shape.\n", "Screen->OpeningWipe(int32_t)", 0, bosMAX-1);
35799 shape = bosCIRCLE;
35800 }
35801 openscreen(shape);
35802 }
35803 void FFScript::do_closescreenshape()
35804 {
35805 int32_t shape = get_register(sarg1) / 10000;
35806 if(shape < 0 || shape >= bosMAX)
35807 {
35808 Z_scripterrlog("Invalid shape passed to %s! Valid range %d to %d. Using 'Circle' shape.\n", "Screen->ClosingWipe(int32_t)", 0, bosMAX-1);
35809 shape = bosCIRCLE;
35810 }
35811 closescreen(shape);
35812 }
35813 void FFScript::do_wavyin() { wavyin(); }
35814 void FFScript::do_wavyout() { wavyout(false); }
35815
35816
35817 void FFScript::do_triggersecret(const bool v)
35818 {
35819 int32_t ID = vbound((SH::get_arg(sarg1, v) / 10000), 0, 255);
35820 mapscr *s = hero_scr;
35821 //Convert a flag type to a secret type.
35822 int32_t ft = combo_trigger_flag_to_secret_combo_index(ID);
35823 if (ft != -1)
35824 {
35825 for(int32_t iter=0; iter<2; ++iter)
35826 {
35827 for ( int32_t q = 0; q < 176; q++ )
35828 {
35829 //Placed flags
35830 if ( iter == 1 )
35831 {
35832 if ( s->sflag[q] == ID ) {
35833 auto rpos_handle = get_rpos_handle_for_screen(s->screen, 0, q);
35834 screen_combo_modify_preroutine(rpos_handle);
35835 s->data[q] = s->secretcombo[ft];
35836 s->cset[q] = s->secretcset[ft];
35837 s->sflag[q] = s->secretflag[ft];
35838 screen_combo_modify_postroutine(rpos_handle);
35839 }
35840 }
35841 //Inherent flags
35842 else
35843 {
35844 if ( combobuf[s->data[q]].flag == ID ) {
35845 auto rpos_handle = get_rpos_handle_for_screen(s->screen, 0, q);
35846 screen_combo_modify_preroutine(rpos_handle);
35847 s->data[q] = s->secretcombo[ft];
35848 s->cset[q] = s->secretcset[ft];
35849 screen_combo_modify_postroutine(rpos_handle);
35850 }
35851
35852 }
35853 }
35854 }
35855 }
35856
35857 }
35858 //NPCData
35859
35860 //NPCData Getter Macros
35861
35862
35863
35864
35865 //NPCData-> Function
35866 #define GET_NPCDATA_FUNCTION_VAR_INT(member) \
35867 { \
35868 int32_t ID = get_register(sarg2) / 10000; \
35869 if(ID < 1 || ID > (MAXGUYS-1)) \
35870 set_register(sarg1, -10000); \
35871 else \
35872 set_register(sarg1, guysbuf[ID].member * 10000); \
35873 }
35874
35875 #define GET_NPCDATA_FUNCTION_VAR_INDEX(member, indexbound) \
35876 { \
35877 int32_t ID = int32_t(ri->d[rINDEX] / 10000);\
35878 int32_t indx = vbound((ri->d[rINDEX2] / 10000), 0, indexbound); \
35879 if(ID < 1 || ID > (MAXGUYS-1)) \
35880 set_register(sarg1, -10000); \
35881 else \
35882 set_register(sarg1, guysbuf[ID].member[indx] * 10000); \
35883 }
35884
35885 #define GET_NPCDATA_FUNCTION_VAR_FLAG(member) \
35886 { \
35887 int32_t ID = int32_t(ri->d[rINDEX] / 10000);\
35888 int32_t flag = int32_t(ri->d[rINDEX2] / 10000);\
35889 if(ID < 1 || ID > (MAXGUYS-1)) \
35890 set_register(sarg1, -10000); \
35891 else \
35892 set_register(sarg1, (guysbuf[ID].member&flag) ? 10000 : 0); \
35893 }
35894
35895 uint32_t get_upper_half_uint64(uint64_t value)
35896 {
35897 return value >> 32;
35898 }
35899
35900 uint32_t get_lower_half_uint64(uint64_t value)
35901 {
35902 return value & 0xFFFFFFFF;
35903 }
35904
35905 // Defunct.
35906 void FFScript::getNPCData_flags(){
35907 int32_t ID = get_register(sarg2) / 10000;
35908 if(ID < 1 || ID > (MAXGUYS-1))
35909 set_register(sarg1, -10000);
35910 else
35911 set_register(sarg1, get_upper_half_uint64(guysbuf[ID].flags) * 10000);
35912 }
35913
35914 // Defunct.
35915 void FFScript::getNPCData_flags2(){
35916 int32_t ID = get_register(sarg2) / 10000;
35917 if(ID < 1 || ID > (MAXGUYS-1))
35918 set_register(sarg1, -10000);
35919 else
35920 set_register(sarg1, get_lower_half_uint64(guysbuf[ID].flags) * 10000);
35921 }
35922
35923 void FFScript::getNPCData_tile() { GET_NPCDATA_FUNCTION_VAR_INT(tile); }
35924 void FFScript::getNPCData_width(){ GET_NPCDATA_FUNCTION_VAR_INT(width); }
35925 void FFScript::getNPCData_height(){ GET_NPCDATA_FUNCTION_VAR_INT(height); }
35926 void FFScript::getNPCData_s_tile(){ GET_NPCDATA_FUNCTION_VAR_INT(s_tile); }
35927 void FFScript::getNPCData_s_width(){ GET_NPCDATA_FUNCTION_VAR_INT(s_width); }
35928 void FFScript::getNPCData_s_height(){ GET_NPCDATA_FUNCTION_VAR_INT(s_height); }
35929 void FFScript::getNPCData_e_tile(){ GET_NPCDATA_FUNCTION_VAR_INT(e_tile); }
35930 void FFScript::getNPCData_e_width(){ GET_NPCDATA_FUNCTION_VAR_INT(e_width); }
35931 void FFScript::getNPCData_e_height() { GET_NPCDATA_FUNCTION_VAR_INT(e_height); }
35932 void FFScript::getNPCData_hp(){ GET_NPCDATA_FUNCTION_VAR_INT(hp); }
35933 void FFScript::getNPCData_family(){ GET_NPCDATA_FUNCTION_VAR_INT(family); }
35934 void FFScript::getNPCData_cset(){ GET_NPCDATA_FUNCTION_VAR_INT(cset); }
35935 void FFScript::getNPCData_anim(){ GET_NPCDATA_FUNCTION_VAR_INT(anim); }
35936 void FFScript::getNPCData_e_anim(){ GET_NPCDATA_FUNCTION_VAR_INT(e_anim); }
35937 void FFScript::getNPCData_frate(){ GET_NPCDATA_FUNCTION_VAR_INT(frate); }
35938 void FFScript::getNPCData_e_frate(){ GET_NPCDATA_FUNCTION_VAR_INT(e_frate); }
35939 void FFScript::getNPCData_dp(){ GET_NPCDATA_FUNCTION_VAR_INT(dp); }
35940 void FFScript::getNPCData_wdp(){ GET_NPCDATA_FUNCTION_VAR_INT(wdp); }
35941 void FFScript::getNPCData_weapon(){ GET_NPCDATA_FUNCTION_VAR_INT(weapon); }
35942 void FFScript::getNPCData_rate(){ GET_NPCDATA_FUNCTION_VAR_INT(rate); }
35943 void FFScript::getNPCData_hrate(){ GET_NPCDATA_FUNCTION_VAR_INT(hrate); }
35944 void FFScript::getNPCData_step(){ GET_NPCDATA_FUNCTION_VAR_INT(step); }
35945 void FFScript::getNPCData_homing(){ GET_NPCDATA_FUNCTION_VAR_INT(homing); }
35946 void FFScript::getNPCData_grumble(){ GET_NPCDATA_FUNCTION_VAR_INT(grumble); }
35947 void FFScript::getNPCData_item_set(){ GET_NPCDATA_FUNCTION_VAR_INT(item_set); }
35948 void FFScript::getNPCData_bgsfx(){ GET_NPCDATA_FUNCTION_VAR_INT(bgsfx); }
35949 void FFScript::getNPCData_hitsfx(){ GET_NPCDATA_FUNCTION_VAR_INT(hitsfx); }
35950 void FFScript::getNPCData_deadsfx(){ GET_NPCDATA_FUNCTION_VAR_INT(deadsfx); }
35951 void FFScript::getNPCData_xofs(){ GET_NPCDATA_FUNCTION_VAR_INT(xofs); }
35952 void FFScript::getNPCData_yofs(){ GET_NPCDATA_FUNCTION_VAR_INT(yofs); }
35953 void FFScript::getNPCData_zofs(){ GET_NPCDATA_FUNCTION_VAR_INT(zofs); }
35954 void FFScript::getNPCData_hxofs(){ GET_NPCDATA_FUNCTION_VAR_INT(hxofs); }
35955 void FFScript::getNPCData_hyofs(){ GET_NPCDATA_FUNCTION_VAR_INT(hyofs); }
35956 void FFScript::getNPCData_hxsz(){ GET_NPCDATA_FUNCTION_VAR_INT(hxsz); }
35957 void FFScript::getNPCData_hysz(){ GET_NPCDATA_FUNCTION_VAR_INT(hysz); }
35958 void FFScript::getNPCData_hzsz(){ GET_NPCDATA_FUNCTION_VAR_INT(hzsz); }
35959 void FFScript::getNPCData_txsz(){ GET_NPCDATA_FUNCTION_VAR_INT(txsz); }
35960 void FFScript::getNPCData_tysz(){ GET_NPCDATA_FUNCTION_VAR_INT(tysz); }
35961 void FFScript::getNPCData_wpnsprite(){ GET_NPCDATA_FUNCTION_VAR_INT(wpnsprite); }
35962 void FFScript::getNPCData_firesfx() { GET_NPCDATA_FUNCTION_VAR_INT(firesfx); }
35963
35964
35965 void FFScript::getNPCData_defense(){GET_NPCDATA_FUNCTION_VAR_INDEX(defense,int32_t(edefLAST255))};
35966
35967
35968 void FFScript::getNPCData_SIZEflags(){GET_NPCDATA_FUNCTION_VAR_FLAG(SIZEflags);}
35969
35970
35971 void FFScript::getNPCData_misc()
35972 {
35973 int32_t ID = int32_t(ri->d[rINDEX] / 10000); //the enemy ID value
35974 int32_t indx = int32_t(ri->d[rINDEX2] / 10000); //the misc index ID
35975 if ((ID < 1 || ID > 511) || ( indx < 0 || indx >= MAX_NPC_ATTRIBUTES ))
35976 set_register(sarg1, -10000);
35977 else set_register(sarg1, guysbuf[ID].attributes[indx] * 10000);
35978 }
35979
35980 //NPCData Setters, two inputs, no return; similar to void GetDMapIntro(int32_t DMap, int32_t buffer[]);
35981
35982 /*
35983
35984 void do_getdmapintro(const bool v)
35985 {
35986 int32_t ID = SH::get_arg(sarg1, v) / 10000;
35987 int32_t arrayptr = get_register(sarg2) / 10000;
35988
35989 if(BC::checkDMapID(ID, "Game->GetDMapIntro") != SH::_NoError)
35990 return;
35991
35992 if(ArrayH::setArray(arrayptr, string(DMaps[ID].intro)) == SH::_Overflow)
35993 Z_scripterrlog("Array supplied to 'Game->GetDMapIntro' not large enough\n");
35994 }
35995
35996 */
35997
35998 //NPCData Setter Macros
35999
36000 //Variables for spritedata sp->member
36001
36002
36003
36004 //Functions for NPCData->
36005
36006 #define SET_NPCDATA_FUNCTION_VAR_INT(member, bound) \
36007 { \
36008 int32_t ID = get_register(sarg1) / 10000; \
36009 int32_t val = get_register(sarg2) / 10000; \
36010 if(ID < 1 || ID > (MAXGUYS-1)) \
36011 set_register(sarg1, -10000); \
36012 else \
36013 guysbuf[ID].member = vbound(val,0,bound); \
36014 }
36015
36016 #define SET_NPCDATA_FUNCTION_VAR_ENUM(member, bound) \
36017 { \
36018 int32_t ID = get_register(sarg1) / 10000; \
36019 int32_t val = get_register(sarg2) / 10000; \
36020 if(ID < 1 || ID > (MAXGUYS-1)) \
36021 set_register(sarg1, -10000); \
36022 else \
36023 guysbuf[ID].member = (decltype(guysbuf[ID].member))vbound(val,0,bound); \
36024 }
36025
36026
36027 #define SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(member) \
36028 { \
36029 int32_t ID = get_register(sarg1) / 10000; \
36030 int32_t val = get_register(sarg2) / 10000; \
36031 if(ID < 1 || ID > (MAXGUYS-1)) \
36032 set_register(sarg1, -10000); \
36033 else \
36034 guysbuf[ID].member = val; \
36035 }
36036
36037
36038 //SET_NPC_VAR_INDEX(member,value)
36039 #define SET_NPCDATA_FUNCTION_VAR_INDEX(member, val, bound, indexbound) \
36040 { \
36041 int32_t ID = (ri->d[rINDEX]/10000); \
36042 int32_t indx = vbound((ri->d[rINDEX2]/10000),0,indexbound); \
36043 if(ID < 1 || ID > (MAXGUYS-1)) \
36044 return; \
36045 else \
36046 guysbuf[ID].member[indx] = vbound(val,0,bound); \
36047 }
36048
36049 //Special case for flags, three inputs one return
36050 #define SET_NPCDATA_FUNCTION_VAR_FLAG(member, val) \
36051 { \
36052 int32_t ID = (ri->d[rINDEX]/10000); \
36053 int32_t flag = (ri->d[rINDEX2]/10000); \
36054 if(ID < 1 || ID > (MAXGUYS-1)) \
36055 return; \
36056 else \
36057 { \
36058 if ( val != 0 ) guysbuf[ID].member|=flag; \
36059 else guysbuf[ID].member|= ~flag; \
36060 }\
36061 }
36062
36063 static uint64_t set_upper_half_uint64(uint64_t num, uint32_t half)
36064 {
36065 uint64_t lower = num & 0x00000000FFFFFFFF;
36066 return lower | ((uint64_t)half << 32);
36067 }
36068
36069 static uint64_t set_lower_half_uint64(uint64_t num, uint32_t half)
36070 {
36071 uint64_t upper = num & 0xFFFFFFFF00000000;
36072 return upper | half;
36073 }
36074
36075 // Defunct.
36076 void FFScript::setNPCData_flags(){
36077 int32_t ID = get_register(sarg1) / 10000;
36078 int32_t val = get_register(sarg2) / 10000;
36079 if(ID < 1 || ID > (MAXGUYS-1))
36080 set_register(sarg1, -10000);
36081 else
36082 {
36083 guysbuf[ID].flags = (guy_flags)set_upper_half_uint64(guysbuf[ID].flags, vbound(val, 0, 0x7FFFFFFF));
36084 }
36085 }
36086
36087 // Defunct.
36088 void FFScript::setNPCData_flags2(){
36089 int32_t ID = get_register(sarg1) / 10000;
36090 int32_t val = get_register(sarg2) / 10000;
36091 if(ID < 1 || ID > (MAXGUYS-1))
36092 set_register(sarg1, -10000);
36093 else
36094 {
36095 guysbuf[ID].flags = (guy_flags)set_lower_half_uint64(guysbuf[ID].flags, vbound(val, 0, 0x7FFFFFFF));
36096 }
36097 }
36098 void FFScript::setNPCData_tile() { SET_NPCDATA_FUNCTION_VAR_INT(tile, ZS_WORD); }
36099 void FFScript::setNPCData_width(){SET_NPCDATA_FUNCTION_VAR_INT(width,ZS_BYTE);}
36100 void FFScript::setNPCData_height(){SET_NPCDATA_FUNCTION_VAR_INT(height,ZS_BYTE);}
36101 void FFScript::setNPCData_s_tile(){SET_NPCDATA_FUNCTION_VAR_INT(s_tile,ZS_WORD);}
36102 void FFScript::setNPCData_s_width(){SET_NPCDATA_FUNCTION_VAR_INT(s_width,ZS_BYTE);}
36103 void FFScript::setNPCData_s_height(){SET_NPCDATA_FUNCTION_VAR_INT(s_height,ZS_BYTE);}
36104 void FFScript::setNPCData_e_tile(){SET_NPCDATA_FUNCTION_VAR_INT(e_tile,ZS_WORD);}
36105 void FFScript::setNPCData_e_width(){SET_NPCDATA_FUNCTION_VAR_INT(e_width,ZS_BYTE);}
36106 void FFScript::setNPCData_e_height() { SET_NPCDATA_FUNCTION_VAR_INT(e_height, ZS_BYTE); }
36107 void FFScript::setNPCData_hp(){SET_NPCDATA_FUNCTION_VAR_INT(hp,ZS_SHORT);}
36108 void FFScript::setNPCData_family(){SET_NPCDATA_FUNCTION_VAR_INT(family,ZS_SHORT);}
36109 void FFScript::setNPCData_cset(){SET_NPCDATA_FUNCTION_VAR_INT(cset,ZS_SHORT);}
36110 void FFScript::setNPCData_anim(){SET_NPCDATA_FUNCTION_VAR_INT(anim,ZS_SHORT);}
36111 void FFScript::setNPCData_e_anim(){SET_NPCDATA_FUNCTION_VAR_INT(e_anim,ZS_SHORT);}
36112 void FFScript::setNPCData_frate(){SET_NPCDATA_FUNCTION_VAR_INT(frate,ZS_SHORT);}
36113 void FFScript::setNPCData_e_frate(){SET_NPCDATA_FUNCTION_VAR_INT(e_frate,ZS_SHORT);}
36114 void FFScript::setNPCData_dp(){SET_NPCDATA_FUNCTION_VAR_INT(dp,ZS_SHORT);}
36115 void FFScript::setNPCData_wdp(){SET_NPCDATA_FUNCTION_VAR_INT(wdp,ZS_SHORT);}
36116 void FFScript::setNPCData_weapon(){SET_NPCDATA_FUNCTION_VAR_INT(weapon,ZS_SHORT);}
36117 void FFScript::setNPCData_rate(){SET_NPCDATA_FUNCTION_VAR_INT(rate,ZS_SHORT);}
36118 void FFScript::setNPCData_hrate(){SET_NPCDATA_FUNCTION_VAR_INT(hrate,ZS_SHORT);}
36119 void FFScript::setNPCData_step(){SET_NPCDATA_FUNCTION_VAR_INT(step,ZS_SHORT);}
36120 void FFScript::setNPCData_homing(){SET_NPCDATA_FUNCTION_VAR_INT(homing,ZS_SHORT);}
36121 void FFScript::setNPCData_grumble(){SET_NPCDATA_FUNCTION_VAR_INT(grumble,ZS_SHORT);}
36122 void FFScript::setNPCData_item_set(){SET_NPCDATA_FUNCTION_VAR_INT(item_set,ZS_SHORT);}
36123 void FFScript::setNPCData_bgsfx(){SET_NPCDATA_FUNCTION_VAR_INT(bgsfx,ZS_SHORT);}
36124 void FFScript::setNPCData_hitsfx(){SET_NPCDATA_FUNCTION_VAR_INT(hitsfx,ZS_BYTE);}
36125 void FFScript::setNPCData_deadsfx(){SET_NPCDATA_FUNCTION_VAR_INT(deadsfx,ZS_BYTE);}
36126 void FFScript::setNPCData_xofs(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(xofs);}
36127 void FFScript::setNPCData_yofs(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(yofs);}
36128 void FFScript::setNPCData_zofs(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(zofs);}
36129 void FFScript::setNPCData_hxofs(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(hxofs);}
36130 void FFScript::setNPCData_hyofs(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(hyofs);}
36131 void FFScript::setNPCData_hxsz(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(hxsz);}
36132 void FFScript::setNPCData_hysz(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(hysz);}
36133 void FFScript::setNPCData_hzsz(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(hzsz);}
36134 void FFScript::setNPCData_txsz(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(txsz);}
36135 void FFScript::setNPCData_tysz(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(tysz);}
36136 void FFScript::setNPCData_wpnsprite(){SET_NPCDATA_FUNCTION_VAR_INT(wpnsprite,511);}
36137 void FFScript::setNPCData_firesfx() { SET_NPCDATA_FUNCTION_VAR_INT(firesfx, 255); }
36138
36139 //NPCData Setters, three inputs, no return. works as SetDMapScreenD function
36140
36141
36142
36143
36144
36145
36146
36147 void FFScript::setNPCData_defense(int32_t v){SET_NPCDATA_FUNCTION_VAR_INDEX(defense,v, ZS_INT, int32_t(edefLAST255) );}
36148 void FFScript::setNPCData_SIZEflags(int32_t v){SET_NPCDATA_FUNCTION_VAR_FLAG(SIZEflags,v);}
36149 void FFScript::setNPCData_misc(int32_t val)
36150 {
36151 int32_t ID = int32_t(ri->d[rINDEX] / 10000); //the enemy ID value
36152 int32_t indx = int32_t(ri->d[rINDEX2] / 10000); //the misc index ID
36153 if ((ID < 1 || ID > 511) || ( indx < 0 || indx >= MAX_NPC_ATTRIBUTES )) return;
36154 guysbuf[ID].attributes[indx] = val;
36155
36156 };
36157
36158 //ComboData
36159
36160 //Macros
36161
36162 //Are these right? newcombo is *combo_class_buf and the others are *combobuf
36163
36164 //Getters for ComboData 'Type' submembers.
36165 #define GET_COMBODATA_TYPE_INT(member) \
36166 { \
36167 int32_t ID = vbound((get_register(sarg2) / 10000),0,MAXCOMBOS);\
36168 set_register(sarg1, combo_class_buf[combobuf[ID].type].member * 10000); \
36169 }
36170
36171 //this may need additional macros.
36172 //for combo_class_buf[ID].member ?
36173 //I'm not sure which it needs to be at present.
36174
36175 #define GET_COMBODATA_TYPE_INDEX(member, bound) \
36176 { \
36177 int32_t ID = int32_t(vbound((ri->d[rINDEX] / 10000),0,MAXCOMBOS));\
36178 int32_t indx = int32_t(vbound((ri->d[rINDEX2] / 10000), 0, bound));\
36179 set_register(sarg1, combo_class_buf[combobuf[ID].type].member[indx] * 10000); \
36180 }
36181
36182 #define GET_COMBODATA_TYPE_FLAG(member) \
36183 { \
36184 int32_t ID = int32_t(vbound(ri->d[rINDEX] / 10000),0,MAXCOMBOS);\
36185 int32_t flag = int32_t(ri->d[rINDEX2] / 10000);\
36186 set_register(sarg1, (combo_class_buf[combobuf[ID].type].member&flag) ? 10000 : 0); \
36187 }
36188
36189
36190
36191 //Getters for ComboData main members.
36192 #define GET_COMBODATA_VAR_INT(member) \
36193 { \
36194 int32_t ID = vbound( (get_register(sarg2) / 10000), 0, MAXCOMBOS);\
36195 set_register(sarg1, combobuf[ID].member * 10000); \
36196 }
36197
36198 #define GET_COMBODATA_VAR_INDEX(member, bound) \
36199 { \
36200 int32_t ID = int32_t( vbound( (ri->d[rINDEX] / 10000),0,MAXCOMBOS) );\
36201 int32_t indx = int32_t ( vbound( (ri->d[rINDEX2] / 10000),0,bound) );\
36202 set_register(sarg1, combobuf[ID].member[indx] * 10000); \
36203 }
36204
36205 #define GET_COMBODATA_VAR_FLAG(member) \
36206 { \
36207 int32_t ID = int32_t( vbound( ( ri->d[rINDEX] / 10000),0,MAXCOMBOS) );\
36208 int32_t flag = int32_t(ri->d[rINDEX2] / 10000);\
36209 set_register(sarg1, (combobuf[ID].member&flag) ? 10000 : 0); \
36210 }
36211
36212
36213
36214 //ComboData Setter Macros
36215
36216 //Setters for ComboData 'type' submembers.
36217 #define SET_COMBODATA_TYPE_INT(member, bound) \
36218 { \
36219 int32_t ID = get_register(sarg1) / 10000; \
36220 int32_t val = vbound( (get_register(sarg2) / 10000), 0, bound); \
36221 if(ID < 1 || ID > 511) \
36222 set_register(sarg1, -10000); \
36223 else \
36224 combo_class_buf[combobuf[ID].type].member = val; \
36225 }
36226
36227 #define SET_COMBODATA_TYPE_INDEX(member, val, bound, indexbound) \
36228 { \
36229 int32_t ID = vbound((ri->d[rINDEX]/10000),0,MAXCOMBOS); \
36230 int32_t indx = vbound((ri->d[rINDEX2]/10000),0,indexbound); \
36231 combo_class_buf[combobuf[ID].type].member[indx] = vbound(val,0,bound); \
36232 }
36233
36234 #define SET_COMBODATA_TYPE_FLAG(member, val, bound) \
36235 { \
36236 int32_t ID = vbound((ri->d[rINDEX]/10000),0,MAXCOMBOS); \
36237 int32_t flag = (ri->d[rINDEX2]/10000); \
36238 combo_class_buf[combobuf[ID].type].member&flag = ((vbound(val,0,bound))!=0); \
36239 \
36240
36241
36242 //Setters for ComboData main members
36243 #define SET_COMBODATA_VAR_INT(member, bound) \
36244 { \
36245 int32_t ID = vbound( (get_register(sarg1) / 10000), 0, MAXCOMBOS); \
36246 int32_t val = vbound((get_register(sarg2) / 10000),0,bound); \
36247 screen_combo_modify_pre(ID); \
36248 combobuf[ID].member = val; \
36249 screen_combo_modify_post(ID); \
36250 }
36251
36252 //SET_NPC_VAR_INDEX(member,value)
36253 #define SET_COMBODATA_VAR_INDEX(member, val, bound, indexbound) \
36254 { \
36255 int32_t ID = vbound((ri->d[rINDEX]/10000),0,MAXCOMBOS); \
36256 int32_t indx = vbound((ri->d[rINDEX2]/10000),0,indexbound); \
36257 combobuf[ID].member[indx] = vbound(val,0,bound); \
36258 }
36259
36260 //Special case for flags, three inputs one return
36261 #define SET_COMBODATA_VAR_FLAG(member, val, bound) \
36262 { \
36263 int32_t ID = vbound((ri->d[rINDEX]/10000),0,MAXCOMBOS); \
36264 int32_t flag = (ri->d[rINDEX2]/10000); \
36265 else \
36266 { \
36267 combobuf[ID].member&flag = ((bvound(val,0,bound))!=0); \
36268 }\
36269 }
36270
36271 //Getters
36272
36273 //one input, one return
36274 void FFScript::getComboData_block_enemies(){ GET_COMBODATA_TYPE_INT(block_enemies); } //byte a
36275 void FFScript::getComboData_block_hole(){ GET_COMBODATA_TYPE_INT(block_hole); } //byte b
36276 void FFScript::getComboData_block_trigger(){ GET_COMBODATA_TYPE_INT(block_trigger); } //byte c
36277 void FFScript::getComboData_conveyor_x_speed(){ GET_COMBODATA_TYPE_INT(conveyor_x_speed); } //int16_t e
36278 void FFScript::getComboData_conveyor_y_speed(){ GET_COMBODATA_TYPE_INT(conveyor_y_speed); } //int16_t f
36279 void FFScript::getComboData_create_enemy(){ GET_COMBODATA_TYPE_INT(create_enemy); } //word g
36280 void FFScript::getComboData_create_enemy_when(){ GET_COMBODATA_TYPE_INT(create_enemy_when); } //byte h
36281 void FFScript::getComboData_create_enemy_change(){ GET_COMBODATA_TYPE_INT(create_enemy_change); } //int32_t i
36282 void FFScript::getComboData_directional_change_type(){ GET_COMBODATA_TYPE_INT(directional_change_type); } //byte j
36283 void FFScript::getComboData_distance_change_tiles(){ GET_COMBODATA_TYPE_INT(distance_change_tiles); } //int32_t k
36284 void FFScript::getComboData_dive_item(){ GET_COMBODATA_TYPE_INT(dive_item); } //int16_t l
36285 void FFScript::getComboData_dock(){ GET_COMBODATA_TYPE_INT(dock); } //byte m
36286 void FFScript::getComboData_fairy(){ GET_COMBODATA_TYPE_INT(fairy); } //byte n
36287 void FFScript::getComboData_ff_combo_attr_change(){ GET_COMBODATA_TYPE_INT(ff_combo_attr_change); } //byte o
36288 void FFScript::getComboData_foot_decorations_tile(){ GET_COMBODATA_TYPE_INT(foot_decorations_tile); } //int32_t p
36289 void FFScript::getComboData_foot_decorations_type(){ GET_COMBODATA_TYPE_INT(foot_decorations_type); } //byte q
36290 void FFScript::getComboData_hookshot_grab_point(){ GET_COMBODATA_TYPE_INT(hookshot_grab_point); } //byte r
36291 void FFScript::getComboData_ladder_pass(){ GET_COMBODATA_TYPE_INT(ladder_pass); } //byte s
36292 void FFScript::getComboData_lock_block_type(){ GET_COMBODATA_TYPE_INT(lock_block_type); } //byte t
36293 void FFScript::getComboData_lock_block_change(){ GET_COMBODATA_TYPE_INT(lock_block_change); } //int32_t u
36294 void FFScript::getComboData_magic_mirror_type(){ GET_COMBODATA_TYPE_INT(magic_mirror_type); } //byte v
36295 void FFScript::getComboData_modify_hp_amount(){ GET_COMBODATA_TYPE_INT(modify_hp_amount); } //int16_t w
36296 void FFScript::getComboData_modify_hp_delay(){ GET_COMBODATA_TYPE_INT(modify_hp_delay); } //byte x
36297 void FFScript::getComboData_modify_hp_type(){ GET_COMBODATA_TYPE_INT(modify_hp_type); } //byte y
36298 void FFScript::getComboData_modify_mp_amount(){ GET_COMBODATA_TYPE_INT(modify_mp_amount); } //int16_t z
36299 void FFScript::getComboData_modify_mp_delay(){ GET_COMBODATA_TYPE_INT(modify_mp_delay); } //byte aa
36300 void FFScript::getComboData_modify_mp_type(){ GET_COMBODATA_TYPE_INT(modify_mp_type); } //byte ab
36301 void FFScript::getComboData_no_push_blocks(){ GET_COMBODATA_TYPE_INT(no_push_blocks); } //byte ac
36302 void FFScript::getComboData_overhead(){ GET_COMBODATA_TYPE_INT(overhead); } //byte ad
36303 void FFScript::getComboData_place_enemy(){ GET_COMBODATA_TYPE_INT(place_enemy); } //byte ae
36304 void FFScript::getComboData_push_direction(){ GET_COMBODATA_TYPE_INT(push_direction); } //byte af
36305 void FFScript::getComboData_push_weight(){ GET_COMBODATA_TYPE_INT(push_weight); } //byte ag heavy or not
36306 void FFScript::getComboData_push_wait(){ GET_COMBODATA_TYPE_INT(push_wait); } //byte ah
36307 void FFScript::getComboData_pushed(){ GET_COMBODATA_TYPE_INT(pushed); } //byte ai
36308 void FFScript::getComboData_raft(){ GET_COMBODATA_TYPE_INT(raft); } //byte aj
36309 void FFScript::getComboData_reset_room(){ GET_COMBODATA_TYPE_INT(reset_room); } //byte ak
36310 void FFScript::getComboData_save_point_type(){ GET_COMBODATA_TYPE_INT(save_point_type); } //byte al
36311 void FFScript::getComboData_screen_freeze_type(){ GET_COMBODATA_TYPE_INT(screen_freeze_type); } //byte am
36312
36313 void FFScript::getComboData_secret_combo(){ GET_COMBODATA_TYPE_INT(secret_combo); } //byte an
36314 void FFScript::getComboData_singular(){ GET_COMBODATA_TYPE_INT(singular); } //byte ao
36315 void FFScript::getComboData_slow_movement(){ GET_COMBODATA_TYPE_INT(slow_movement); } //byte ap
36316 void FFScript::getComboData_statue_type(){ GET_COMBODATA_TYPE_INT(statue_type); } //byte aq
36317 void FFScript::getComboData_step_type(){ GET_COMBODATA_TYPE_INT(step_type); } //byte ar
36318 void FFScript::getComboData_step_change_to(){ GET_COMBODATA_TYPE_INT(step_change_to); } //int32_t as
36319 void FFScript::getComboData_strike_remnants(){ GET_COMBODATA_TYPE_INT(strike_remnants); } //int32_t au
36320 void FFScript::getComboData_strike_remnants_type(){ GET_COMBODATA_TYPE_INT(strike_remnants_type); } //byte av
36321 void FFScript::getComboData_strike_change(){ GET_COMBODATA_TYPE_INT(strike_change); } //int32_t aw
36322 void FFScript::getComboData_strike_item(){ GET_COMBODATA_TYPE_INT(strike_item); } //int16_t ax
36323 void FFScript::getComboData_touch_item(){ GET_COMBODATA_TYPE_INT(touch_item); } //int16_t ay
36324 void FFScript::getComboData_touch_stairs(){ GET_COMBODATA_TYPE_INT(touch_stairs); } //byte az
36325 void FFScript::getComboData_trigger_type(){ GET_COMBODATA_TYPE_INT(trigger_type); } //byte ba
36326 void FFScript::getComboData_trigger_sensitive(){ GET_COMBODATA_TYPE_INT(trigger_sensitive); } //byte bb
36327 void FFScript::getComboData_warp_type(){ GET_COMBODATA_TYPE_INT(warp_type); } //byte bc
36328 void FFScript::getComboData_warp_sensitive(){ GET_COMBODATA_TYPE_INT(warp_sensitive); } //byte bd
36329 void FFScript::getComboData_warp_direct(){ GET_COMBODATA_TYPE_INT(warp_direct); } //byte be
36330 void FFScript::getComboData_warp_location(){ GET_COMBODATA_TYPE_INT(warp_location); } //byte bf
36331 void FFScript::getComboData_water(){ GET_COMBODATA_TYPE_INT(water); } //byte bg
36332 void FFScript::getComboData_whistle(){ GET_COMBODATA_TYPE_INT(whistle); } //byte bh
36333 void FFScript::getComboData_win_game(){ GET_COMBODATA_TYPE_INT(win_game); } //byte bi
36334 void FFScript::getComboData_block_weapon_lvl(){ GET_COMBODATA_TYPE_INT(block_weapon_lvl); } //byte bj - max level of weapon to block
36335
36336 void FFScript::getComboData_tile(){ GET_COMBODATA_VAR_INT(tile); } //newcombo, word
36337 void FFScript::getComboData_flip(){ GET_COMBODATA_VAR_INT(flip); } //newcombo byte
36338
36339 void FFScript::getComboData_walk(){ GET_COMBODATA_VAR_INT(walk); } //newcombo byte
36340 void FFScript::getComboData_type(){ GET_COMBODATA_VAR_INT(type); } //newcombo byte
36341 void FFScript::getComboData_csets(){ GET_COMBODATA_VAR_INT(csets); } //newcombo byte
36342 void FFScript::getComboData_frames(){ GET_COMBODATA_VAR_INT(frames); } //newcombo byte
36343 void FFScript::getComboData_speed(){ GET_COMBODATA_VAR_INT(speed); } //newcombo byte
36344 void FFScript::getComboData_nextcombo(){ GET_COMBODATA_VAR_INT(nextcombo); } //newcombo word
36345 void FFScript::getComboData_nextcset(){ GET_COMBODATA_VAR_INT(nextcset); } //newcombo byte
36346 void FFScript::getComboData_flag(){ GET_COMBODATA_VAR_INT(flag); } //newcombo byte
36347 void FFScript::getComboData_skipanim(){ GET_COMBODATA_VAR_INT(skipanim); } //newcombo byte
36348 void FFScript::getComboData_nexttimer(){ GET_COMBODATA_VAR_INT(nexttimer); } //newcombo word
36349 void FFScript::getComboData_skipanimy(){ GET_COMBODATA_VAR_INT(skipanimy); } //newcombo byte
36350 void FFScript::getComboData_animflags(){ GET_COMBODATA_VAR_INT(animflags); } //newcombo byte
36351
36352
36353 //two inputs, one return
36354 void FFScript::getComboData_block_weapon(){ GET_COMBODATA_TYPE_INDEX(block_weapon,32); } //byte array[32] d (ID of LWeapon)
36355 void FFScript::getComboData_expansion(){ GET_COMBODATA_VAR_INDEX(expansion,6); } //newcombo byte, arr[6]
36356 void FFScript::getComboData_strike_weapons(){ GET_COMBODATA_TYPE_INDEX(strike_weapons,32); } //byte at, arr[32]
36357
36358 //Setters, two inputs no returns
36359
36360 void FFScript::setComboData_block_enemies(){ SET_COMBODATA_TYPE_INT(block_enemies,ZS_BYTE); } //byte a
36361 void FFScript::setComboData_block_hole(){ SET_COMBODATA_TYPE_INT(block_hole,ZS_BYTE); } //byte b
36362 void FFScript::setComboData_block_trigger(){ SET_COMBODATA_TYPE_INT(block_trigger,ZS_BYTE); } //byte c
36363 void FFScript::setComboData_conveyor_x_speed(){ SET_COMBODATA_TYPE_INT(conveyor_x_speed,ZS_SHORT); } //int16_t e
36364 void FFScript::setComboData_conveyor_y_speed(){ SET_COMBODATA_TYPE_INT(conveyor_y_speed,ZS_SHORT); } //int16_t f
36365 void FFScript::setComboData_create_enemy(){ SET_COMBODATA_TYPE_INT(create_enemy,ZS_WORD); } //word g
36366 void FFScript::setComboData_create_enemy_when(){ SET_COMBODATA_TYPE_INT(create_enemy_when,ZS_BYTE); } //byte h
36367 void FFScript::setComboData_create_enemy_change(){ SET_COMBODATA_TYPE_INT(create_enemy_change,ZS_LONG); } //int32_t i
36368 void FFScript::setComboData_directional_change_type(){ SET_COMBODATA_TYPE_INT(directional_change_type,ZS_BYTE); } //byte j
36369 void FFScript::setComboData_distance_change_tiles(){ SET_COMBODATA_TYPE_INT(distance_change_tiles,ZS_LONG); } //int32_t k
36370 void FFScript::setComboData_dive_item(){ SET_COMBODATA_TYPE_INT(dive_item,ZS_SHORT); } //int16_t l
36371 void FFScript::setComboData_dock(){ SET_COMBODATA_TYPE_INT(dock,ZS_BYTE); } //byte m
36372 void FFScript::setComboData_fairy(){ SET_COMBODATA_TYPE_INT(fairy,ZS_BYTE); } //byte n
36373 void FFScript::setComboData_ff_combo_attr_change(){ SET_COMBODATA_TYPE_INT(ff_combo_attr_change,ZS_BYTE); } //byte o
36374 void FFScript::setComboData_foot_decorations_tile(){ SET_COMBODATA_TYPE_INT(foot_decorations_tile,ZS_LONG); } //int32_t p
36375 void FFScript::setComboData_foot_decorations_type(){ SET_COMBODATA_TYPE_INT(foot_decorations_type,ZS_BYTE); } //byte q
36376 void FFScript::setComboData_hookshot_grab_point(){ SET_COMBODATA_TYPE_INT(hookshot_grab_point,ZS_BYTE); } //byte r
36377 void FFScript::setComboData_ladder_pass(){ SET_COMBODATA_TYPE_INT(ladder_pass,ZS_BYTE); } //byte s
36378 void FFScript::setComboData_lock_block_type(){ SET_COMBODATA_TYPE_INT(lock_block_type,ZS_BYTE); } //byte t
36379 void FFScript::setComboData_lock_block_change(){ SET_COMBODATA_TYPE_INT(lock_block_change,ZS_LONG); } //int32_t u
36380 void FFScript::setComboData_magic_mirror_type(){ SET_COMBODATA_TYPE_INT(magic_mirror_type,ZS_BYTE); } //byte v
36381 void FFScript::setComboData_modify_hp_amount(){ SET_COMBODATA_TYPE_INT(modify_hp_amount,ZS_SHORT); } //int16_t w
36382 void FFScript::setComboData_modify_hp_delay(){ SET_COMBODATA_TYPE_INT(modify_hp_delay,ZS_BYTE); } //byte x
36383 void FFScript::setComboData_modify_hp_type(){ SET_COMBODATA_TYPE_INT(modify_hp_type,ZS_BYTE); } //byte y
36384 void FFScript::setComboData_modify_mp_amount(){ SET_COMBODATA_TYPE_INT(modify_mp_amount,ZS_SHORT); } //int16_t z
36385 void FFScript::setComboData_modify_mp_delay(){ SET_COMBODATA_TYPE_INT(modify_mp_delay,ZS_BYTE); } //byte aa
36386 void FFScript::setComboData_modify_mp_type(){ SET_COMBODATA_TYPE_INT(modify_mp_type,ZS_BYTE); } //byte ab
36387 void FFScript::setComboData_no_push_blocks(){ SET_COMBODATA_TYPE_INT(no_push_blocks,ZS_BYTE); } //byte ac
36388 void FFScript::setComboData_overhead(){ SET_COMBODATA_TYPE_INT(overhead,ZS_BYTE); } //byte ad
36389 void FFScript::setComboData_place_enemy(){ SET_COMBODATA_TYPE_INT(place_enemy,ZS_BYTE); } //byte ae
36390 void FFScript::setComboData_push_direction(){ SET_COMBODATA_TYPE_INT(push_direction,ZS_BYTE); } //byte af
36391 void FFScript::setComboData_push_weight(){ SET_COMBODATA_TYPE_INT(push_weight,ZS_BYTE); } //byte ag heavy or not
36392 void FFScript::setComboData_push_wait(){ SET_COMBODATA_TYPE_INT(push_wait,ZS_BYTE); } //byte ah
36393 void FFScript::setComboData_pushed(){ SET_COMBODATA_TYPE_INT(pushed,ZS_BYTE); } //byte ai
36394 void FFScript::setComboData_raft(){ SET_COMBODATA_TYPE_INT(raft,ZS_BYTE); } //byte aj
36395 void FFScript::setComboData_reset_room(){ SET_COMBODATA_TYPE_INT(reset_room,ZS_BYTE); } //byte ak
36396 void FFScript::setComboData_save_point_type(){ SET_COMBODATA_TYPE_INT(save_point_type,ZS_BYTE); } //byte al
36397 void FFScript::setComboData_screen_freeze_type(){ SET_COMBODATA_TYPE_INT(screen_freeze_type,ZS_BYTE); } //byte am
36398
36399 void FFScript::setComboData_secret_combo(){ SET_COMBODATA_TYPE_INT(secret_combo,ZS_BYTE); } //byte an
36400 void FFScript::setComboData_singular(){ SET_COMBODATA_TYPE_INT(singular,ZS_BYTE); } //byte ao
36401 void FFScript::setComboData_slow_movement(){ SET_COMBODATA_TYPE_INT(slow_movement,ZS_BYTE); } //byte ap
36402 void FFScript::setComboData_statue_type(){ SET_COMBODATA_TYPE_INT(statue_type,ZS_BYTE); } //byte aq
36403 void FFScript::setComboData_step_type(){ SET_COMBODATA_TYPE_INT(step_type,ZS_BYTE); } //byte ar
36404 void FFScript::setComboData_step_change_to(){ SET_COMBODATA_TYPE_INT(step_change_to,ZS_LONG); } //int32_t as
36405
36406 void FFScript::setComboData_strike_remnants(){ SET_COMBODATA_TYPE_INT(strike_remnants,ZS_LONG); } //int32_t au
36407 void FFScript::setComboData_strike_remnants_type(){ SET_COMBODATA_TYPE_INT(strike_remnants_type,ZS_BYTE); } //byte av
36408 void FFScript::setComboData_strike_change(){ SET_COMBODATA_TYPE_INT(strike_change,ZS_LONG); } //int32_t aw
36409 void FFScript::setComboData_strike_item(){ SET_COMBODATA_TYPE_INT(strike_item,ZS_SHORT); } //int16_t ax
36410 void FFScript::setComboData_touch_item(){ SET_COMBODATA_TYPE_INT(touch_item,ZS_SHORT); } //int16_t ay
36411 void FFScript::setComboData_touch_stairs(){ SET_COMBODATA_TYPE_INT(touch_stairs,ZS_BYTE); } //byte az
36412 void FFScript::setComboData_trigger_type(){ SET_COMBODATA_TYPE_INT(trigger_type,ZS_BYTE); } //byte ba
36413 void FFScript::setComboData_trigger_sensitive(){ SET_COMBODATA_TYPE_INT(trigger_sensitive,ZS_BYTE); } //byte bb
36414 void FFScript::setComboData_warp_type(){ SET_COMBODATA_TYPE_INT(warp_type,ZS_BYTE); } //byte bc
36415 void FFScript::setComboData_warp_sensitive(){ SET_COMBODATA_TYPE_INT(warp_sensitive,ZS_BYTE); } //byte bd
36416 void FFScript::setComboData_warp_direct(){ SET_COMBODATA_TYPE_INT(warp_direct,ZS_BYTE); } //byte be
36417 void FFScript::setComboData_warp_location(){ SET_COMBODATA_TYPE_INT(warp_location,ZS_BYTE); } //byte bf
36418 void FFScript::setComboData_water(){ SET_COMBODATA_TYPE_INT(water,ZS_BYTE); } //byte bg
36419 void FFScript::setComboData_whistle(){ SET_COMBODATA_TYPE_INT(whistle,ZS_BYTE); } //byte bh
36420 void FFScript::setComboData_win_game(){ SET_COMBODATA_TYPE_INT(win_game,ZS_BYTE); } //byte bi
36421 void FFScript::setComboData_block_weapon_lvl(){ SET_COMBODATA_TYPE_INT(block_weapon_lvl,ZS_BYTE); } //byte bj - max level of weapon to block
36422
36423 //combobuf
36424 void FFScript::setComboData_tile(){ SET_COMBODATA_VAR_INT(tile,ZS_WORD); } //newcombo, word
36425 void FFScript::setComboData_flip(){ SET_COMBODATA_VAR_INT(flip,ZS_BYTE); } //newcombo byte
36426
36427 void FFScript::setComboData_walk(){ SET_COMBODATA_VAR_INT(walk,ZS_BYTE); } //newcombo byte
36428 void FFScript::setComboData_type(){ SET_COMBODATA_VAR_INT(type,ZS_BYTE); } //newcombo byte
36429 void FFScript::setComboData_csets(){ SET_COMBODATA_VAR_INT(csets,ZS_BYTE); } //newcombo byte
36430 void FFScript::setComboData_frames(){ SET_COMBODATA_VAR_INT(frames,ZS_BYTE); } //newcombo byte
36431 void FFScript::setComboData_speed(){ SET_COMBODATA_VAR_INT(speed,ZS_BYTE); } //newcombo byte
36432 void FFScript::setComboData_nextcombo(){ SET_COMBODATA_VAR_INT(nextcombo,ZS_WORD); } //newcombo word
36433 void FFScript::setComboData_nextcset(){ SET_COMBODATA_VAR_INT(nextcset,ZS_BYTE); } //newcombo byte
36434 void FFScript::setComboData_flag(){ SET_COMBODATA_VAR_INT(flag,ZS_BYTE); } //newcombo byte
36435 void FFScript::setComboData_skipanim(){ SET_COMBODATA_VAR_INT(skipanim,ZS_BYTE); } //newcombo byte
36436 void FFScript::setComboData_nexttimer(){ SET_COMBODATA_VAR_INT(nexttimer,ZS_WORD); } //newcombo word
36437 void FFScript::setComboData_skipanimy(){ SET_COMBODATA_VAR_INT(skipanimy,ZS_BYTE); } //newcombo byte
36438 void FFScript::setComboData_animflags(){ SET_COMBODATA_VAR_INT(animflags,ZS_BYTE); } //newcombo byte
36439
36440 //three inputs, no returns
36441 void FFScript::setComboData_block_weapon(int32_t v){ SET_COMBODATA_TYPE_INDEX(block_weapon,v,ZS_BYTE,32); } //byte array[32] d (ID of LWeapon)
36442 void FFScript::setComboData_strike_weapons(int32_t v){ SET_COMBODATA_TYPE_INDEX(strike_weapons,v,ZS_BYTE,32); } //byte at, arr[32]
36443 void FFScript::setComboData_expansion(int32_t v){ SET_COMBODATA_VAR_INDEX(expansion,v,ZS_BYTE,6); } //newcombo byte, arr[6]
36444
36445 //SpriteData Macros
36446 #define GET_SPRITEDATA_TYPE_INT(member) \
36447 { \
36448 int32_t ID = vbound((get_register(sarg2) / 10000),0,255);\
36449 set_register(sarg1, wpnsbuf[ID].member * 10000); \
36450 }
36451
36452 #define SET_SPRITEDATA_TYPE_INT(member, bound) \
36453 { \
36454 int32_t ID = get_register(sarg1) / 10000; \
36455 int32_t val = vbound( (get_register(sarg2) / 10000), 0, bound); \
36456 if(ID < 1 || ID > 255) \
36457 set_register(sarg1, -10000); \
36458 else \
36459 wpnsbuf[ID].member = val; \
36460 }
36461
36462 #define SET_SPRITEDATA_TYPE_INT_NOBOUND(member) \
36463 { \
36464 int32_t ID = get_register(sarg1) / 10000; \
36465 int32_t val = get_register(sarg2) / 10000; \
36466 if(ID < 1 || ID > 255) \
36467 set_register(sarg1, -10000); \
36468 else \
36469 wpnsbuf[ID].member = val; \
36470 }
36471
36472
36473 void FFScript::getSpriteDataTile(){GET_SPRITEDATA_TYPE_INT(tile);}
36474 void FFScript::getSpriteDataMisc(){GET_SPRITEDATA_TYPE_INT(misc);}
36475 void FFScript::getSpriteDataCSets(){GET_SPRITEDATA_TYPE_INT(csets);}
36476 void FFScript::getSpriteDataFrames(){GET_SPRITEDATA_TYPE_INT(frames);}
36477 void FFScript::getSpriteDataSpeed(){GET_SPRITEDATA_TYPE_INT(speed);}
36478 void FFScript::getSpriteDataType(){GET_SPRITEDATA_TYPE_INT(type);}
36479
36480
36481
36482 void FFScript::setSpriteDataTile(){SET_SPRITEDATA_TYPE_INT(tile,ZS_WORD);}
36483 void FFScript::setSpriteDataMisc(){SET_SPRITEDATA_TYPE_INT(misc,ZS_CHAR);}
36484 void FFScript::setSpriteDataCSets(){SET_SPRITEDATA_TYPE_INT(csets,ZS_CHAR);}
36485 void FFScript::setSpriteDataFrames(){SET_SPRITEDATA_TYPE_INT(frames,ZS_CHAR);}
36486 void FFScript::setSpriteDataSpeed(){SET_SPRITEDATA_TYPE_INT(speed,ZS_CHAR);}
36487 void FFScript::setSpriteDataType(){SET_SPRITEDATA_TYPE_INT(type,ZS_CHAR);}
36488
36489
36490 2004 void FFScript::do_setMIDI_volume(int32_t m)
36491 {
36492 2004 master_volume(-1,(vbound(m,0,255)));
36493 2004 }
36494 2004 void FFScript::do_setMusic_volume(int32_t m)
36495 {
36496 2004 emusic_volume = vbound(m,0,255);
36497 2004 }
36498 2004 void FFScript::do_setDIGI_volume(int32_t m)
36499 {
36500 2004 master_volume((vbound(m,0,255)),-1);
36501 2004 }
36502 void FFScript::do_setSFX_volume(int32_t m)
36503 {
36504 sfx_volume = m;
36505 }
36506 void FFScript::do_setSFX_pan(int32_t m)
36507 {
36508 pan_style = vbound(m,0,3);
36509 }
36510 8 int32_t FFScript::do_getMIDI_volume()
36511 {
36512 8 return ((int32_t)midi_volume);
36513 }
36514 8 int32_t FFScript::do_getMusic_volume()
36515 {
36516 8 return ((int32_t)emusic_volume);
36517 }
36518 8 int32_t FFScript::do_getDIGI_volume()
36519 {
36520 8 return ((int32_t)digi_volume);
36521 }
36522 int32_t FFScript::do_getSFX_volume()
36523 {
36524 return ((int32_t)sfx_volume);
36525 }
36526 int32_t FFScript::do_getSFX_pan()
36527 {
36528 return ((int32_t)pan_style);
36529 }
36530
36531
36532 //Change Game Over Screen Values
36533 void FFScript::FFSetSaveScreenSetting()
36534 {
36535
36536 int32_t indx = get_register(sarg1) / 10000;
36537 int32_t value = get_register(sarg2) / 10000; //bounded in zelda.cpp
36538 if(indx < 0 || indx > 11)
36539 set_register(sarg1, -10000);
36540 else
36541 SetSaveScreenSetting(indx, value);
36542 }
36543
36544
36545
36546 void FFScript::FFChangeSubscreenText()
36547 {
36548
36549 int32_t index = get_register(sarg1) / 10000;
36550 int32_t arrayptr = get_register(sarg2) / 10000;
36551
36552 if ( index < 0 || index > 3 )
36553 {
36554 al_trace("The index supplied to Game->SetSubscreenText() is invalid. The index specified was: %d /n", index);
36555 return;
36556 }
36557
36558 string filename_str;
36559 ArrayH::getString(arrayptr, filename_str, 73);
36560 ChangeSubscreenText(index,filename_str.c_str());
36561 }
36562
36563 20 void FFScript::SetItemMessagePlayed(int32_t itm)
36564 {
36565 20 game->item_messages_played[itm] = 1;
36566 20 }
36567 15 bool FFScript::GetItemMessagePlayed(int32_t itm)
36568 {
36569 15 return ((game->item_messages_played[itm] ) ? true : false);
36570 }
36571
36572 int32_t FFScript::getQRBit(int32_t rule)
36573 {
36574 return ( get_qr(rule) ? 1 : 0 );
36575 }
36576
36577 25663301 void FFScript::setHeroAction(int32_t a)
36578 {
36579 25663301 FF_hero_action = vbound(a, 0, 255);
36580 25663301 }
36581
36582 92529429 int32_t FFScript::getHeroAction()
36583 {
36584 92529429 int32_t special_action = Hero.getAction2();
36585
2/2
✓ Branch 0 taken 558431 times.
✓ Branch 1 taken 91970998 times.
92529429 if ( special_action != -1 ) return special_action; //spin, dive, charge
36586 91970998 else return FF_hero_action; //everything else
36587 92529429 }
36588
36589 1094 void FFScript::init()
36590 {
36591 1094 apply_qr_rules();
36592 1094 eventData.clear();
36593 1094 countGenScripts();
36594
2/2
✓ Branch 0 taken 10940 times.
✓ Branch 1 taken 1094 times.
12034 for ( int32_t q = 0; q < wexLast; q++ ) warpex[q] = 0;
36595 1094 temp_no_stepforward = 0;
36596 1094 nostepforward = 0;
36597 1094 numscriptdraws = 0;
36598 1094 skipscriptdraws = false;
36599 1094 max_ff_rules = qr_MAX;
36600 1094 coreflags = 0;
36601 1094 skip_ending_credits = 0;
36602 1094 music_update_cond = 0;
36603 1094 music_update_flags = 0;
36604 //quest_format : is this properly initialised?
36605
2/2
✓ Branch 0 taken 74392 times.
✓ Branch 1 taken 1094 times.
75486 for ( int32_t q = 0; q < susptLAST; q++ ) { system_suspend[q] = 0; }
36606
36607 1094 usr_midi_volume = midi_volume;
36608 1094 usr_digi_volume = digi_volume;
36609 1094 usr_sfx_volume = sfx_volume;
36610 1094 usr_music_volume = emusic_volume;
36611
36612 1094 usr_panstyle = pan_style;
36613 1094 FF_hero_action = 0;
36614 1094 enemy_removal_point[spriteremovalY1] = -32767;
36615 1094 enemy_removal_point[spriteremovalY2] = 32767;
36616 1094 enemy_removal_point[spriteremovalX1] = -32767;
36617 1094 enemy_removal_point[spriteremovalX2] = 32767;
36618 1094 enemy_removal_point[spriteremovalZ1] = -32767;
36619 1094 enemy_removal_point[spriteremovalZ2] = 32767;
36620
36621
2/2
✓ Branch 0 taken 4376 times.
✓ Branch 1 taken 1094 times.
5470 for ( int32_t q = 0; q < 4; q++ )
36622 {
36623 4376 FF_screenbounds[q] = 0;
36624 4376 FF_screen_dimensions[q] = 0;
36625 4376 FF_subscreen_dimensions[q] = 0;
36626 4376 FF_eweapon_removal_bounds[q] = 0;
36627 4376 FF_lweapon_removal_bounds[q] = 0;
36628 4376 }
36629
2/2
✓ Branch 0 taken 10940 times.
✓ Branch 1 taken 1094 times.
12034 for ( int32_t q = 0; q < FFSCRIPTCLASS_CLOCKS; q++ )
36630 {
36631 10940 FF_clocks[q] = 0;
36632 10940 }
36633
2/2
✓ Branch 0 taken 21880 times.
✓ Branch 1 taken 1094 times.
22974 for ( int32_t q = 0; q < SCRIPT_DRAWING_RULES; q++ )
36634 {
36635 21880 ScriptDrawingRules[q] = 0;
36636 21880 }
36637
2/2
✓ Branch 0 taken 6564 times.
✓ Branch 1 taken 1094 times.
7658 for ( int32_t q = 0; q < NUM_USER_MIDI_OVERRIDES; q++ )
36638 {
36639 6564 FF_UserMidis[q] = 0;
36640 6564 }
36641 1094 subscreen_scroll_speed = 0; //make a define for a default and read quest override! -Z
36642 1094 kb_typing_mode = false;
36643 1094 initIncludePaths();
36644 //clearRunningItemScripts();
36645 1094 ScrollingScreensAll.clear();
36646 1094 memset(ScrollingData, 0, sizeof(int32_t) * SZ_SCROLLDATA);
36647 1094 ScrollingData[SCROLLDATA_DIR] = -1;
36648 1094 user_rng_init();
36649 1094 clear_script_engine_data();
36650
2/2
✓ Branch 0 taken 71987 times.
✓ Branch 1 taken 1094 times.
73081 for (auto &it : jitted_scripts)
36651 {
36652
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71987 times.
71987 if (it.second) jit_delete_script_handle(it.second);
36653 }
36654 1094 jitted_scripts.clear();
36655 1094 script_debug_handles.clear();
36656 1094 runtime_script_debug_handle = nullptr;
36657 1094 }
36658
36659 308 void FFScript::shutdown()
36660 {
36661
2/2
✓ Branch 0 taken 6583 times.
✓ Branch 1 taken 308 times.
6891 for (auto &it : jitted_scripts)
36662 {
36663
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6580 times.
6583 if (it.second) jit_delete_script_handle(it.second);
36664 }
36665 308 jitted_scripts.clear();
36666 308 objectRAM.clear();
36667 308 script_objects.clear();
36668 308 }
36669
36670
36671 12 void FFScript::SetFFEngineFlag(int32_t flag, bool state)
36672 {
36673
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if ( state ) { coreflags |= flag; }
36674 else coreflags &= ~flag;
36675 12 }
36676
36677 void FFScript::setSubscreenScrollSpeed(byte n)
36678 {
36679 subscreen_scroll_speed = n;
36680 }
36681
36682 int32_t FFScript::getSubscreenScrollSpeed()
36683 {
36684 return (int32_t)subscreen_scroll_speed;
36685 }
36686
36687 void FFScript::do_greyscale(const bool v)
36688 {
36689 // This has been removed.
36690 }
36691
36692 void FFScript::do_monochromatic(const bool v)
36693 {
36694 // This has been removed.
36695 }
36696
36697 10680 static int convert_6bit_to_8bit_color_shift_arg(int v)
36698 {
36699 10680 int va = abs(v);
36700
2/2
✓ Branch 0 taken 10677 times.
✓ Branch 1 taken 3 times.
10680 if (va < 64)
36701 10677 return _rgb_scale_6[va] * sign(v);
36702
36703 3 int vdiv = va / 63;
36704 3 int vmod = va % 63;
36705 3 return (vdiv * 255 + _rgb_scale_6[vmod]) * sign(v);
36706 10680 }
36707
36708 void FFScript::gfxmonohue()
36709 {
36710 int32_t r = SH::read_stack(ri->sp + 3) / 10000;
36711 int32_t g = SH::read_stack(ri->sp + 2) / 10000;
36712 int32_t b = SH::read_stack(ri->sp + 1) / 10000;
36713 if (!scripting_use_8bit_colors)
36714 {
36715 r = convert_6bit_to_8bit_color_shift_arg(r);
36716 g = convert_6bit_to_8bit_color_shift_arg(g);
36717 b = convert_6bit_to_8bit_color_shift_arg(b);
36718 }
36719 bool m = (SH::read_stack(ri->sp + 0) / 10000);
36720 doGFXMonohue(r,g,b,m);
36721 }
36722
36723 66 void FFScript::clearTint()
36724 {
36725 66 doClearTint();
36726 66 }
36727
36728 3560 void FFScript::Tint()
36729 {
36730 3560 int32_t r = SH::read_stack(ri->sp + 2) / 10000;
36731 3560 int32_t g = SH::read_stack(ri->sp + 1) / 10000;
36732 3560 int32_t b = SH::read_stack(ri->sp + 0) / 10000;
36733
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3560 times.
3560 if (!scripting_use_8bit_colors)
36734 {
36735 3560 r = convert_6bit_to_8bit_color_shift_arg(r);
36736 3560 g = convert_6bit_to_8bit_color_shift_arg(g);
36737 3560 b = convert_6bit_to_8bit_color_shift_arg(b);
36738 3560 }
36739 3560 doTint(r,g,b);
36740 3560 }
36741
36742 void FFScript::do_fx_zap(const bool v)
36743 {
36744 int32_t out = SH::get_arg(sarg1, v);
36745
36746 if ( out ) { FFScript::do_zapout(); }
36747 else FFScript::do_zapin();
36748 }
36749
36750 void FFScript::do_fx_wavy(const bool v)
36751 {
36752 int32_t out = SH::get_arg(sarg1, v);
36753
36754 if ( out ) { FFScript::do_wavyout(); }
36755 else FFScript::do_wavyin();
36756 }
36757
36758 486873447 int32_t FFScript::getQuestHeaderInfo(int32_t type)
36759 {
36760 486873447 return quest_format[type];
36761 }
36762
36763 string get_filestr(const bool relative, bool is_file) //Used for 'FileSystem' functions.
36764 {
36765 int32_t strptr = get_register(sarg1)/10000;
36766 string user_path;
36767 ArrayH::getString(strptr, user_path, 512);
36768
36769 if (!relative)
36770 {
36771 user_path = user_path.substr(user_path.find_first_not_of('/'),string::npos); //Kill leading '/'
36772 size_t last = user_path.find_last_not_of('/');
36773 if(last!=string::npos)++last;
36774 user_path = user_path.substr(0,last); //Kill trailing '/'
36775 return user_path;
36776 }
36777
36778 if (auto r = parse_user_path(user_path, is_file); !r)
36779 {
36780 scripting_log_error_with_context("Error: {}", r.error());
36781 return "";
36782 } else return r.value();
36783 }
36784
36785 void FFScript::do_checkdir(const bool is_dir)
36786 {
36787 string resolved_path = get_filestr(get_qr(qr_BITMAP_AND_FILESYSTEM_PATHS_ALWAYS_RELATIVE), false);
36788 set_register(sarg1, !resolved_path.empty() && checkPath(resolved_path.c_str(), is_dir) ? 10000 : 0);
36789 }
36790
36791 void FFScript::do_fs_remove()
36792 {
36793 string resolved_path = get_filestr(true, true);
36794 set_register(sarg1, !resolved_path.empty() && remove(resolved_path.c_str()) ? 0 : 10000);
36795 }
36796
36797 100 void FFScript::Play_Level_Music()
36798 {
36799 100 int32_t m = hero_scr->screen_midi;
36800
36801
1/6
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
100 switch(m)
36802 {
36803 case -2:
36804 music_stop();
36805 break;
36806
36807 case -1:
36808 100 play_DmapMusic();
36809 100 break;
36810
36811 case 1:
36812 jukebox(ZC_MIDI_OVERWORLD);
36813 break;
36814
36815 case 2:
36816 jukebox(ZC_MIDI_DUNGEON);
36817 break;
36818
36819 case 3:
36820 jukebox(ZC_MIDI_LEVEL9);
36821 break;
36822
36823 default:
36824 if(m>=4 && m<4+MAXCUSTOMMIDIS)
36825 jukebox(m+MIDIOFFSET_MAPSCR);
36826 else
36827 music_stop();
36828 }
36829 100 }
36830
36831 92 void FFScript::do_warp_ex(bool v)
36832 {
36833 92 int32_t zscript_array_ptr = SH::get_arg(sarg1, v) / 10000;
36834 92 ArrayManager am(zscript_array_ptr);
36835
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if(am.invalid()) return;
36836 92 int32_t zscript_array_size = am.size();
36837
1/2
✓ Branch 0 taken 92 times.
✗ Branch 1 not taken.
92 switch(zscript_array_size)
36838 {
36839 case 8: // {int32_t type, int32_t dmap, int32_t screen, int32_t x, int32_t y, int32_t effect, int32_t sound, int32_t flags}
36840 case 9: // {int32_t type, int32_t dmap, int32_t screen, int32_t x, int32_t y, int32_t effect, int32_t sound, int32_t flags, int32_t dir}
36841 {
36842 92 int32_t tmpwarp[9]={0};
36843
2/2
✓ Branch 0 taken 736 times.
✓ Branch 1 taken 92 times.
828 for ( int32_t q = 0; q < 8; q++ )
36844 {
36845 736 tmpwarp[q] = (am.get(q)/10000);
36846 736 }
36847
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 66 times.
92 tmpwarp[wexDir] = zscript_array_size < 9 ? -1 : (am.get(8)/10000);\
36848
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if ( ((unsigned)tmpwarp[1]) >= MAXDMAPS )
36849 {
36850 Z_scripterrlog("Invalid DMap ID (%d) passed to WarpEx(). Aborting.\n", tmpwarp[1]);
36851 return;
36852 }
36853
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if ( ((unsigned)tmpwarp[2]) >= MAPSCRS )
36854 {
36855 Z_scripterrlog("Invalid Screen Index (%d) passed to WarpEx(). Aborting.\n", tmpwarp[2]);
36856 return;
36857 }
36858 //Extra sanity guard.
36859
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if ( map_screen_index(DMaps[tmpwarp[1]].map, tmpwarp[2] + DMaps[tmpwarp[1]].xoff) >= (int32_t)TheMaps.size() )
36860 {
36861 Z_scripterrlog("Invalid destination passed to WarpEx(). Aborting.\n");
36862 return;
36863 }
36864
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if(get_qr(qr_OLD_BROKEN_WARPEX_MUSIC))
36865 {
36866
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 88 times.
92 SETFLAG(tmpwarp[wexFlags],warpFlagFORCECONTINUEMUSIC,tmpwarp[wexFlags]&warpFlagFORCERESETMUSIC);
36867 92 TOGGLEFLAG(tmpwarp[wexFlags],warpFlagFORCERESETMUSIC);
36868 92 }
36869 //If we passed the sanity checks, populate the FFCore array and begin the action!
36870
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 92 times.
920 for ( int32_t q = 0; q < wexActive; q++ )
36871 {
36872 828 FFCore.warpex[q] = tmpwarp[q];
36873 828 }
36874 92 FFCore.warpex[wexActive] = 1;
36875 92 break;
36876 }
36877
36878 default:
36879 {
36880 Z_scripterrlog("Array supplied to Hero->WarpEx() is the wrong size!\n The array size was: &d, and valid sizes are [8] and [9].\n",zscript_array_size);
36881 break;
36882 }
36883 }
36884 92 }
36885
36886 ///////////////////////////////
36887 //* SCRIPT ENGINE FUNCTIONS *//
36888 ////////////////////////////////////////////////////////////////////////////
36889
36890 void FFScript::clearRunningItemScripts()
36891 {
36892 //for ( byte q = 0; q < 256; q++ ) runningItemScripts[q] = 0;
36893 }
36894
36895
36896 11399 void FFScript::warpScriptCheck()
36897 {
36898
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 11397 times.
11399 if(get_qr(qr_SCRIPTDRAWSINWARPS))
36899 {
36900 2 FFCore.runWarpScripts(false);
36901 2 FFCore.runWarpScripts(true); //Waitdraw
36902 2 }
36903
3/4
✓ Branch 0 taken 819 times.
✓ Branch 1 taken 10578 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 819 times.
11397 else if(get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN) && doscript(ScriptType::ScriptedPassiveSubscreen))
36904 {
36905
1/2
✓ Branch 0 taken 819 times.
✗ Branch 1 not taken.
819 if(DMaps[cur_dmap].passive_sub_script != 0)
36906 ZScriptVersion::RunScript(ScriptType::ScriptedPassiveSubscreen, DMaps[cur_dmap].passive_sub_script, cur_dmap);
36907
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 819 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
819 if (waitdraw(ScriptType::ScriptedPassiveSubscreen) && DMaps[cur_dmap].passive_sub_script != 0 && doscript(ScriptType::ScriptedPassiveSubscreen))
36908 {
36909 ZScriptVersion::RunScript(ScriptType::ScriptedPassiveSubscreen, DMaps[cur_dmap].passive_sub_script, cur_dmap);
36910 waitdraw(ScriptType::ScriptedPassiveSubscreen) = false;
36911 }
36912 819 }
36913 11399 }
36914
36915 4 void FFScript::runWarpScripts(bool waitdraw)
36916 {
36917
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if(waitdraw)
36918 {
36919
3/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 if ((!( FFCore.system_suspend[susptGLOBALGAME] )) && FFCore.waitdraw(ScriptType::Global, GLOBAL_SCRIPT_GAME))
36920 {
36921 1 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_GAME, GLOBAL_SCRIPT_GAME);
36922 1 FFCore.waitdraw(ScriptType::Global, GLOBAL_SCRIPT_GAME) = false;
36923 1 }
36924
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if ( !FFCore.system_suspend[susptITEMSCRIPTENGINE] )
36925 {
36926 2 FFCore.itemScriptEngineOnWaitdraw();
36927 2 }
36928
2/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2 if ( (!( FFCore.system_suspend[susptHEROACTIVE] )) && FFCore.waitdraw(ScriptType::Hero) && FFCore.getQuestHeaderInfo(vZelda) >= 0x255 )
36929 {
36930 ZScriptVersion::RunScript(ScriptType::Hero, SCRIPT_HERO_ACTIVE);
36931 FFCore.waitdraw(ScriptType::Hero) = false;
36932 }
36933
2/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2 if ( (!( FFCore.system_suspend[susptDMAPSCRIPT] )) && FFCore.waitdraw(ScriptType::DMap) && FFCore.getQuestHeaderInfo(vZelda) >= 0x255 )
36934 {
36935 ZScriptVersion::RunScript(ScriptType::DMap, DMaps[cur_dmap].script,cur_dmap);
36936 FFCore.waitdraw(ScriptType::DMap) = false;
36937 }
36938
4/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
2 if ( (!( FFCore.system_suspend[susptDMAPSCRIPT] )) && FFCore.waitdraw(ScriptType::ScriptedPassiveSubscreen) && FFCore.getQuestHeaderInfo(vZelda) >= 0x255 )
36939 {
36940 1 ZScriptVersion::RunScript(ScriptType::ScriptedPassiveSubscreen, DMaps[cur_dmap].passive_sub_script,cur_dmap);
36941 1 FFCore.waitdraw(ScriptType::ScriptedPassiveSubscreen) = false;
36942 1 }
36943 //no doscript check here, becauseb of preload? Do we want to write doscript here? -Z 13th July, 2019
36944
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (FFCore.getQuestHeaderInfo(vZelda) >= 0x255 && !FFCore.system_suspend[susptSCREENSCRIPTS])
36945 {
36946 4 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
36947
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2 if (scr->script != 0 && FFCore.waitdraw(ScriptType::Screen, scr->screen) && scr->preloadscript)
36948 {
36949 ZScriptVersion::RunScript(ScriptType::Screen, scr->script, scr->screen);
36950 FFCore.waitdraw(ScriptType::Screen, scr->screen) = 0;
36951 }
36952 2 });
36953 2 }
36954 2 }
36955 else
36956 {
36957
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if ((!( FFCore.system_suspend[susptGLOBALGAME] )) && FFCore.doscript(ScriptType::Global, GLOBAL_SCRIPT_GAME))
36958 {
36959 2 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_GAME, GLOBAL_SCRIPT_GAME);
36960 2 }
36961
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if ( !FFCore.system_suspend[susptITEMSCRIPTENGINE] )
36962 {
36963 2 FFCore.itemScriptEngine();
36964 2 }
36965
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
2 if ((!( FFCore.system_suspend[susptHEROACTIVE] )) && doscript(ScriptType::Hero) && FFCore.getQuestHeaderInfo(vZelda) >= 0x255)
36966 {
36967 2 ZScriptVersion::RunScript(ScriptType::Hero, SCRIPT_HERO_ACTIVE);
36968 2 }
36969
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
2 if ( (!( FFCore.system_suspend[susptDMAPSCRIPT] )) && doscript(ScriptType::DMap) && FFCore.getQuestHeaderInfo(vZelda) >= 0x255 )
36970 {
36971 2 ZScriptVersion::RunScript(ScriptType::DMap, DMaps[cur_dmap].script,cur_dmap);
36972 2 }
36973
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
2 if ( (!( FFCore.system_suspend[susptDMAPSCRIPT] )) && FFCore.doscript(ScriptType::ScriptedPassiveSubscreen) && FFCore.getQuestHeaderInfo(vZelda) >= 0x255 )
36974 {
36975 2 ZScriptVersion::RunScript(ScriptType::ScriptedPassiveSubscreen, DMaps[cur_dmap].passive_sub_script,cur_dmap);
36976 2 }
36977
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (FFCore.getQuestHeaderInfo(vZelda) >= 0x255 && !FFCore.system_suspend[susptSCREENSCRIPTS])
36978 {
36979 4 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
36980
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 if (scr->script != 0 && scr->preloadscript)
36981 {
36982 ZScriptVersion::RunScript(ScriptType::Screen, scr->script, scr->screen);
36983 }
36984 2 });
36985 2 }
36986 }
36987 4 }
36988
36989 34579710 void FFScript::runF6Engine()
36990 {
36991
5/6
✓ Branch 0 taken 34577942 times.
✓ Branch 1 taken 1768 times.
✓ Branch 2 taken 45 times.
✓ Branch 3 taken 34577897 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 45 times.
34579710 if(!Quit && (GameFlags&GAMEFLAG_TRYQUIT) && !(GameFlags&GAMEFLAG_F6SCRIPT_ACTIVE))
36992 {
36993
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
45 if(globalscripts[GLOBAL_SCRIPT_F6]->valid())
36994 {
36995 //Incase this was called mid-another script, store ref data
36996 push_ri();
36997 //
36998 clear_bitmap(f6_menu_buf);
36999 blit(framebuf, f6_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
37000 initZScriptGlobalScript(GLOBAL_SCRIPT_F6);
37001 int32_t openingwipe = black_opening_count;
37002 int32_t openingshape = black_opening_shape;
37003 black_opening_count = 0; //No opening wipe during F6 menu
37004 if(black_opening_shape==bosFADEBLACK) black_fade(0);
37005 GameFlags |= GAMEFLAG_F6SCRIPT_ACTIVE;
37006 //auto tmpDrawCommands = script_drawing_commands.pop_commands();
37007 pause_all_sfx();
37008
37009 auto& data = get_script_engine_data(ScriptType::Global, GLOBAL_SCRIPT_F6);
37010 while (data.doscript)
37011 {
37012 script_drawing_commands.Clear();
37013 load_control_state();
37014 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_F6, GLOBAL_SCRIPT_F6);
37015 if (data.waitdraw)
37016 {
37017 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_F6, GLOBAL_SCRIPT_F6);
37018 data.waitdraw = false;
37019 }
37020 //Draw
37021 clear_bitmap(framebuf);
37022 if( !FFCore.system_suspend[susptCOMBOANIM] ) animate_combos();
37023 doScriptMenuDraws();
37024 //
37025 advanceframe(true,true,false);
37026 if(Quit) break; //Something quit, end script running
37027 }
37028 resume_all_sfx();
37029 script_drawing_commands.Clear();
37030 //script_drawing_commands.push_commands(tmpDrawCommands);
37031 GameFlags &= ~GAMEFLAG_F6SCRIPT_ACTIVE;
37032 //Restore opening wipe
37033 black_opening_count = openingwipe;
37034 black_opening_shape = openingshape;
37035 if(openingshape == bosFADEBLACK)
37036 {
37037 refreshTints();
37038 memcpy(tempblackpal, RAMpal, PAL_SIZE*sizeof(RGB));
37039 }
37040 //Restore script refinfo
37041 pop_ri();
37042 //
37043 if(!Quit)
37044 {
37045 if(!get_qr(qr_NOCONTINUE))
37046 f_Quit(qQUIT);
37047 }
37048 }
37049 45 else f_Quit(qQUIT);
37050 45 zc_readkey(KEY_F6);
37051 45 GameFlags &= ~GAMEFLAG_TRYQUIT;
37052 45 }
37053 34579710 }
37054 33 void FFScript::runOnDeathEngine()
37055 {
37056
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 2 times.
33 if(!playerscripts[SCRIPT_HERO_DEATH]->valid()) return; //No script to run
37057 2 clear_bitmap(script_menu_buf);
37058 2 blit(framebuf, script_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
37059 2 initZScriptHeroScripts();
37060 2 GameFlags |= GAMEFLAG_SCRIPTMENU_ACTIVE;
37061 2 kill_sfx(); //No need to pause/resume; the player is dead.
37062 //auto tmpDrawCommands = script_drawing_commands.pop_commands();
37063
37064 2 auto& data = get_script_engine_data(ScriptType::Hero);
37065
4/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 803 times.
✓ Branch 2 taken 803 times.
✓ Branch 3 taken 2 times.
805 while (data.doscript && !Quit)
37066 {
37067 803 script_drawing_commands.Clear();
37068 803 load_control_state();
37069 803 ZScriptVersion::RunScript(ScriptType::Hero, SCRIPT_HERO_DEATH);
37070
1/2
✓ Branch 0 taken 803 times.
✗ Branch 1 not taken.
803 if (data.waitdraw)
37071 {
37072 ZScriptVersion::RunScript(ScriptType::Hero, SCRIPT_HERO_DEATH);
37073 data.waitdraw = false;
37074 }
37075 //Draw
37076 803 clear_bitmap(framebuf);
37077
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 803 times.
803 if( !FFCore.system_suspend[susptCOMBOANIM] ) animate_combos();
37078 803 doScriptMenuDraws();
37079 //
37080 803 advanceframe(true);
37081 }
37082 2 script_drawing_commands.Clear();
37083 //script_drawing_commands.push_commands(tmpDrawCommands);
37084 2 GameFlags &= ~GAMEFLAG_SCRIPTMENU_ACTIVE;
37085 33 }
37086 412 void FFScript::runOnLaunchEngine()
37087 {
37088
2/2
✓ Branch 0 taken 407 times.
✓ Branch 1 taken 5 times.
412 if(!globalscripts[GLOBAL_SCRIPT_ONLAUNCH]->valid()) return; //No script to run
37089 //Do NOT blit the prior screen to this bitmap; that would be the TITLE SCREEN.
37090 5 clear_to_color(script_menu_buf,BLACK);
37091 5 initZScriptGlobalScript(GLOBAL_SCRIPT_ONLAUNCH);
37092 5 GameFlags |= GAMEFLAG_SCRIPTMENU_ACTIVE;
37093 //auto tmpDrawCommands = script_drawing_commands.pop_commands();
37094
37095 5 auto& data = get_script_engine_data(ScriptType::Global, GLOBAL_SCRIPT_ONLAUNCH);
37096
4/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 5 times.
11 while (data.doscript && !Quit)
37097 {
37098 6 script_drawing_commands.Clear();
37099 6 load_control_state();
37100 6 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_ONLAUNCH, GLOBAL_SCRIPT_ONLAUNCH);
37101
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (data.waitdraw)
37102 {
37103 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_ONLAUNCH, GLOBAL_SCRIPT_ONLAUNCH);
37104 data.waitdraw = false;
37105 }
37106 //Draw
37107 6 clear_bitmap(framebuf);
37108
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if( !FFCore.system_suspend[susptCOMBOANIM] ) animate_combos();
37109
37110 6 doScriptMenuDraws();
37111 //
37112 6 advanceframe(true);
37113 }
37114 5 script_drawing_commands.Clear();
37115 //script_drawing_commands.push_commands(tmpDrawCommands);
37116 5 GameFlags &= ~GAMEFLAG_SCRIPTMENU_ACTIVE;
37117 412 }
37118 10 bool FFScript::runGenericFrozenEngine(const word script, const int32_t *init_data)
37119 {
37120 10 user_genscript& scr = user_genscript::get(script);
37121
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
10 if(script < 1 || script >= NUMSCRIPTSGENERIC) return false;
37122
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(init_data)
37123 {
37124 for(int q = 0; q < 8; ++q)
37125 scr.initd[q] = init_data[q];
37126 }
37127
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!genericscripts[script]->valid()) return false; //No script to run
37128
37129
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(gen_frozen_index >= 400) // Experimentally tested to crash (stack overflow) at 500 for me -Em
37130 {
37131 Z_scripterrlog("Failed to run frozen generic script; too many (%d) frozen scripts running already! Possible infinite recursion?\n", gen_frozen_index);
37132 return false;
37133 }
37134 //Store script refinfo
37135 10 push_ri();
37136 10 int local_i = int(gen_frozen_index++);
37137 10 reset_script_engine_data(ScriptType::GenericFrozen, local_i);
37138 //run script
37139 10 uint32_t fl = GameFlags & GAMEFLAG_SCRIPTMENU_ACTIVE;
37140 10 BITMAP* tmpbuf = script_menu_buf;
37141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(fl)
37142 {
37143 script_menu_buf = create_bitmap_ex(8, framebuf->w, framebuf->h);
37144 }
37145 10 clear_bitmap(script_menu_buf);
37146 10 blit(framebuf, script_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
37147 10 GameFlags |= GAMEFLAG_SCRIPTMENU_ACTIVE;
37148 //auto tmpDrawCommands = script_drawing_commands.pop_commands();
37149
4/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1542 times.
✓ Branch 2 taken 1542 times.
✓ Branch 3 taken 10 times.
1552 while(doscript(ScriptType::GenericFrozen, local_i) && !Quit)
37150 {
37151 1542 script_drawing_commands.Clear();
37152 1542 load_control_state();
37153 1542 ZScriptVersion::RunScript(ScriptType::GenericFrozen, script, local_i);
37154 //Draw
37155 1542 clear_bitmap(framebuf);
37156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1542 times.
1542 if( !FFCore.system_suspend[susptCOMBOANIM] ) animate_combos();
37157 1542 doScriptMenuDraws();
37158 //
37159 1542 advanceframe(true);
37160 }
37161 10 script_drawing_commands.Clear();
37162 //script_drawing_commands.push_commands(tmpDrawCommands);
37163 //clear
37164 10 GameFlags &= ~GAMEFLAG_SCRIPTMENU_ACTIVE;
37165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(fl)
37166 {
37167 GameFlags |= fl;
37168 destroy_bitmap(script_menu_buf);
37169 script_menu_buf = tmpbuf;
37170 }
37171 10 clear_script_engine_data(ScriptType::GenericFrozen, local_i);
37172 10 --gen_frozen_index;
37173 //Restore script refinfo
37174 10 pop_ri();
37175 10 return true;
37176 10 }
37177
37178 1403 bool FFScript::runScriptedActiveSusbcreen()
37179 {
37180 1403 word activesubscript = DMaps[cur_dmap].active_sub_script;
37181
3/4
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 1362 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 41 times.
1403 if(!activesubscript || !dmapscripts[activesubscript]->valid()) return false; //No script to run
37182 41 word passivesubscript = DMaps[cur_dmap].passive_sub_script;
37183 41 word dmapactivescript = DMaps[cur_dmap].script;
37184 41 clear_bitmap(script_menu_buf);
37185 41 blit(framebuf, script_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
37186 41 initZScriptScriptedActiveSubscreen();
37187 41 GameFlags |= GAMEFLAG_SCRIPTMENU_ACTIVE;
37188 41 word script_dmap = cur_dmap;
37189 //auto tmpDrawCommands = script_drawing_commands.pop_commands();
37190 41 pause_all_sfx();
37191 41 auto& data = get_script_engine_data(ScriptType::ScriptedActiveSubscreen);
37192
4/4
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 6772 times.
✓ Branch 2 taken 6772 times.
✓ Branch 3 taken 41 times.
6813 while (data.doscript && !Quit)
37193 {
37194 6772 script_drawing_commands.Clear();
37195 6772 load_control_state();
37196
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 6772 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
6772 if(get_qr(qr_DMAP_ACTIVE_RUNS_DURING_ACTIVE_SUBSCRIPT) && DMaps[script_dmap].script != 0 && doscript(ScriptType::DMap))
37197 {
37198 ZScriptVersion::RunScript(ScriptType::DMap, dmapactivescript, script_dmap);
37199 }
37200
4/6
✓ Branch 0 taken 140 times.
✓ Branch 1 taken 6632 times.
✓ Branch 2 taken 140 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 140 times.
6772 if(get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_DURING_ACTIVE_SUBSCRIPT)!=0 && DMaps[script_dmap].passive_sub_script != 0 && FFCore.doscript(ScriptType::ScriptedPassiveSubscreen))
37201 {
37202 140 ZScriptVersion::RunScript(ScriptType::ScriptedPassiveSubscreen, passivesubscript, script_dmap);
37203 140 }
37204 6772 ZScriptVersion::RunScript(ScriptType::ScriptedActiveSubscreen, activesubscript, script_dmap);
37205
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6772 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6772 if(waitdraw(ScriptType::DMap) && (get_qr(qr_DMAP_ACTIVE_RUNS_DURING_ACTIVE_SUBSCRIPT) && DMaps[script_dmap].script != 0 && doscript(ScriptType::DMap)))
37206 {
37207 ZScriptVersion::RunScript(ScriptType::DMap, dmapactivescript, script_dmap);
37208 waitdraw(ScriptType::DMap) = false;
37209 }
37210
5/8
✓ Branch 0 taken 139 times.
✓ Branch 1 taken 6633 times.
✓ Branch 2 taken 139 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 139 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 139 times.
6772 if(waitdraw(ScriptType::ScriptedPassiveSubscreen) && (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_DURING_ACTIVE_SUBSCRIPT)!=0 && DMaps[script_dmap].passive_sub_script != 0 && FFCore.doscript(ScriptType::ScriptedPassiveSubscreen)))
37211 {
37212 139 ZScriptVersion::RunScript(ScriptType::ScriptedPassiveSubscreen, passivesubscript, script_dmap);
37213 139 waitdraw(ScriptType::ScriptedPassiveSubscreen) = false;
37214 139 }
37215
3/4
✓ Branch 0 taken 5472 times.
✓ Branch 1 taken 1300 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5472 times.
6772 if (data.waitdraw && data.doscript)
37216 {
37217 5472 ZScriptVersion::RunScript(ScriptType::ScriptedActiveSubscreen, activesubscript, script_dmap);
37218 5472 data.waitdraw = false;
37219 5472 }
37220 //Draw
37221 6772 clear_bitmap(framebuf);
37222
2/4
✓ Branch 0 taken 6772 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6772 times.
6772 if(cur_dmap == script_dmap && ( !FFCore.system_suspend[susptCOMBOANIM] ) ) animate_combos();
37223 6772 doScriptMenuDraws();
37224 //
37225 6772 advanceframe(true);
37226 //Handle warps; run game_loop once!
37227
1/2
✓ Branch 0 taken 6772 times.
✗ Branch 1 not taken.
6772 if(cur_dmap != script_dmap)
37228 {
37229 activesubscript = DMaps[cur_dmap].active_sub_script;
37230 if(!activesubscript || !dmapscripts[activesubscript]->valid()) return true; //No script to run
37231 passivesubscript = DMaps[cur_dmap].passive_sub_script;
37232 dmapactivescript = DMaps[cur_dmap].script;
37233 script_dmap = cur_dmap;
37234 //Reset the background image
37235 game_loop();
37236 clear_bitmap(script_menu_buf);
37237 blit(framebuf, script_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
37238 //Now loop without advancing frame, so that the subscreen script can draw immediately.
37239 }
37240 }
37241 41 resume_all_sfx();
37242 41 script_drawing_commands.Clear();
37243 //script_drawing_commands.push_commands(tmpDrawCommands);
37244 41 GameFlags &= ~GAMEFLAG_SCRIPTMENU_ACTIVE;
37245 41 GameFlags |= GAMEFLAG_RESET_GAME_LOOP;
37246 41 return true;
37247 1403 }
37248 1077 bool FFScript::runOnMapScriptEngine()
37249 {
37250 1077 word onmap_script = DMaps[cur_dmap].onmap_script;
37251
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1074 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
1077 if(!onmap_script || !dmapscripts[onmap_script]->valid()) return false; //No script to run
37252 3 clear_bitmap(script_menu_buf);
37253 3 blit(framebuf, script_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
37254 3 initZScriptOnMapScript();
37255 3 GameFlags |= GAMEFLAG_SCRIPTMENU_ACTIVE;
37256 3 word script_dmap = cur_dmap;
37257 //auto tmpDrawCommands = script_drawing_commands.pop_commands();
37258 3 pause_all_sfx();
37259
37260 3 auto& data = get_script_engine_data(ScriptType::OnMap);
37261
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 114 times.
✓ Branch 2 taken 114 times.
✓ Branch 3 taken 3 times.
117 while (data.doscript && !Quit)
37262 {
37263 114 script_drawing_commands.Clear();
37264 114 load_control_state();
37265 114 ZScriptVersion::RunScript(ScriptType::OnMap, onmap_script, script_dmap);
37266
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
114 if (data.waitdraw && data.doscript)
37267 {
37268 ZScriptVersion::RunScript(ScriptType::OnMap, onmap_script, script_dmap);
37269 data.waitdraw = false;
37270 }
37271 //Draw
37272 114 clear_bitmap(framebuf);
37273
2/4
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 114 times.
114 if(cur_dmap == script_dmap && ( !FFCore.system_suspend[susptCOMBOANIM] ) ) animate_combos();
37274 114 doScriptMenuDraws();
37275 //
37276 114 advanceframe(true);
37277 //Handle warps; run game_loop once!
37278
1/2
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
114 if(cur_dmap != script_dmap)
37279 {
37280 onmap_script = DMaps[cur_dmap].onmap_script;
37281 if(!onmap_script || !dmapscripts[onmap_script]->valid()) return true; //No script to run
37282 script_dmap = cur_dmap;
37283 //Reset the background image
37284 game_loop();
37285 clear_bitmap(script_menu_buf);
37286 blit(framebuf, script_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
37287 //Now loop without advancing frame, so that the subscreen script can draw immediately.
37288 }
37289 }
37290 3 resume_all_sfx();
37291 3 script_drawing_commands.Clear();
37292 //script_drawing_commands.push_commands(tmpDrawCommands);
37293 3 GameFlags &= ~GAMEFLAG_SCRIPTMENU_ACTIVE;
37294 3 GameFlags |= GAMEFLAG_RESET_GAME_LOOP;
37295 3 return true;
37296 1077 }
37297
37298 9237 void FFScript::doScriptMenuDraws()
37299 {
37300
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9237 times.
9237 BITMAP* menu_buf = ((GameFlags & GAMEFLAG_F6SCRIPT_ACTIVE) != 0) ? f6_menu_buf : script_menu_buf;
37301 9237 blit(menu_buf, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
37302 //Script draws
37303 9237 do_script_draws(framebuf, origin_scr, 0, playing_field_offset);
37304 9237 }
37305
37306 264 void FFScript::runOnSaveEngine()
37307 {
37308
1/2
✓ Branch 0 taken 264 times.
✗ Branch 1 not taken.
264 if(globalscripts[GLOBAL_SCRIPT_ONSAVE]->valid())
37309 {
37310 push_ri();
37311 //Prevent getting here via Quit from causing a forced-script-quit after 1000 commands!
37312 int32_t tQuit = Quit;
37313 Quit = 0;
37314 //
37315 initZScriptGlobalScript(GLOBAL_SCRIPT_ONSAVE);
37316 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_ONSAVE, GLOBAL_SCRIPT_ONSAVE);
37317 //
37318 pop_ri();
37319 Quit = tQuit;
37320 }
37321 264 }
37322
37323 15781875 bool FFScript::itemScriptEngine()
37324 {
37325
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15781875 times.
15781875 if ( FFCore.system_suspend[susptITEMSCRIPTENGINE] ) return false;
37326
2/2
✓ Branch 0 taken 4040160000 times.
✓ Branch 1 taken 15781875 times.
4055941875 for ( int32_t q = 0; q < MAXITEMS; q++ )
37327 {
37328
37329
3/4
✓ Branch 0 taken 29532190 times.
✓ Branch 1 taken 4010627810 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 29532190 times.
4040160000 if ( itemsbuf[q].script <= 0 || itemsbuf[q].script > NUMSCRIPTITEM ) continue; // > NUMSCRIPTITEM as someone could force an invaid script slot!
37330
37331 29532190 auto& data = get_script_engine_data(ScriptType::Item, q);
37332
2/2
✓ Branch 0 taken 14167 times.
✓ Branch 1 taken 29518023 times.
29532190 if ( data.doscript < 1 ) continue;
37333
37334 //Passive items
37335
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14167 times.
14167 if (((itemsbuf[q].flags&item_passive_script)))
37336 {
37337 if(game->item[q] && (get_qr(qr_ITEMSCRIPTSKEEPRUNNING)))
37338 {
37339 if(get_qr(qr_PASSIVE_ITEM_SCRIPT_ONLY_HIGHEST)
37340 && current_item(itemsbuf[q].family) > itemsbuf[q].fam_type)
37341 data.doscript = 0;
37342 else ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[q].script, q&0xFFF);
37343 if(!data.doscript) //Item script ended. Clear the data, if any remains.
37344 {
37345 data.ref.Clear();
37346 data.initialized = false;
37347 data.waitdraw = false;
37348 FFScript::deallocateAllScriptOwned(ScriptType::Item, q);
37349 }
37350 }
37351 }
37352 else
37353 {
37354
37355 //Normal Items
37356 /*! What happens here: When an item script is first run by the user using that utem, the script runs for one frame.
37357 After executing RunScript(), item_doscript is set to '1' in hero.cpp.
37358 If the quest allows the item to continue running, the itemScriptEngine() function ignores running the
37359 same item script (again) that frame, and insteads increments item_doscript to '2'.
37360 If item_doscript == 2, then we know we are on the second frame, and we run it perpetually.
37361 If the QR to enable item scripts to run for more than one frame is not enabled, then item_doscript is set to '0'.
37362 If the item flag 'PERPETUAL SCRIPT' is enabled, then we ignore the lack of item_doscript==2.
37363 This allows passive item scripts to function.
37364 */
37365
37366 14167 auto& data = get_script_engine_data(ScriptType::Item, q);
37367
37368
2/2
✓ Branch 0 taken 662 times.
✓ Branch 1 taken 13505 times.
14167 if ( data.doscript == 1 ) // FIrst frame, normally set in hero.cpp
37369 {
37370
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 662 times.
662 if ( get_qr(qr_ITEMSCRIPTSKEEPRUNNING) )
37371 {
37372 662 data.doscript = 2;
37373 662 }
37374 662 }
37375
1/2
✓ Branch 0 taken 13505 times.
✗ Branch 1 not taken.
13505 else if (data.doscript == 2) //Second frame and later, if scripts continue to run.
37376 {
37377 13505 ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[q].script, q&0xFFF);
37378 13505 }
37379 else if (data.doscript == 3) //Run via itemdata->RunScript
37380 {
37381 if ( (get_qr(qr_ITEMSCRIPTSKEEPRUNNING)) )
37382 {
37383 data.doscript = 2; //Reduce to normal run status
37384 }
37385 else
37386 {
37387 ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[q].script, q & 0xFFF);
37388 data.doscript = 0;
37389 }
37390 }
37391 else if(data.doscript==4) //Item set itself false, kill script and clear data here
37392 {
37393 data.doscript = 0;
37394 }
37395
2/2
✓ Branch 0 taken 13490 times.
✓ Branch 1 taken 677 times.
14167 if(data.doscript==0) //Item script ended. Clear the data, if any remains.
37396 {
37397 677 data.ref.Clear();
37398 677 data.initialized = false;
37399 677 data.waitdraw = false;
37400 677 FFScript::deallocateAllScriptOwned(ScriptType::Item, q);
37401 677 }
37402 }
37403 14167 }
37404 15781875 return false;
37405 15781875 }
37406
37407 16271246 bool FFScript::itemScriptEngineOnWaitdraw()
37408 {
37409
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16271246 times.
16271246 if ( FFCore.system_suspend[susptITEMSCRIPTENGINE] ) return false;
37410
2/2
✓ Branch 0 taken 4165438976 times.
✓ Branch 1 taken 16271246 times.
4181710222 for ( int32_t q = 0; q < MAXITEMS; q++ )
37411 {
37412
3/4
✓ Branch 0 taken 31392395 times.
✓ Branch 1 taken 4134046581 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 31392395 times.
4165438976 if ( itemsbuf[q].script <= 0 || itemsbuf[q].script > NUMSCRIPTITEM ) continue; // > NUMSCRIPTITEM as someone could force an invaid script slot!
37413
37414 31392395 auto& data = get_script_engine_data(ScriptType::Item, q);
37415
37416
2/2
✓ Branch 0 taken 13491 times.
✓ Branch 1 taken 31378904 times.
31392395 if ( data.doscript < 1 ) continue;
37417
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13491 times.
13491 if (!data.waitdraw) continue;
37418 else data.waitdraw = false;
37419
37420 /*! What happens here: When an item script is first run by the user using that utem, the script runs for one frame.
37421 After executing RunScript(), item_doscript is set to '1' in hero.cpp.
37422 If the quest allows the item to continue running, the itemScriptEngine() function ignores running the
37423 same item script (again) that frame, and insteads increments item_doscript to '2'.
37424 If item_doscript == 2, then we know we are on the second frame, and we run it perpetually.
37425 If the QR to enable item scripts to run for more than one frame is not enabled, then item_doscript is set to '0'.
37426 If the item flag 'PERPETUAL SCRIPT' is enabled, then we ignore the lack of item_doscript==2.
37427 This allows passive item scripts to function.
37428 */
37429 //Passive items
37430 if ((itemsbuf[q].flags&item_passive_script))
37431 {
37432 if(game->item[q] && (get_qr(qr_ITEMSCRIPTSKEEPRUNNING)))
37433 {
37434 if(get_qr(qr_PASSIVE_ITEM_SCRIPT_ONLY_HIGHEST)
37435 && current_item(itemsbuf[q].family) > itemsbuf[q].fam_type)
37436 data.doscript = 0;
37437 else ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[q].script, q&0xFFF);
37438 if(!data.doscript) //Item script ended. Clear the data, if any remains.
37439 {
37440 data.ref.Clear();
37441 data.initialized = false;
37442 data.waitdraw = false;
37443 FFScript::deallocateAllScriptOwned(ScriptType::Item, q);
37444 }
37445 }
37446 }
37447 else
37448 {
37449 //Normal items
37450 if ( data.doscript == 1 ) // FIrst frame, normally set in hero.cpp
37451 {
37452 if ( get_qr(qr_ITEMSCRIPTSKEEPRUNNING) )
37453 {
37454 data.doscript = 2;
37455 }
37456 else data.doscript = 0;
37457 }
37458 else if (data.doscript == 2) //Second frame and later, if scripts continue to run.
37459 {
37460 ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[q].script, q&0xFFF);
37461 }
37462 else if (data.doscript == 3) //Run via itemdata->RunScript
37463 {
37464 if ( (get_qr(qr_ITEMSCRIPTSKEEPRUNNING)) )
37465 {
37466 data.doscript = 2; //Reduce to normal run status
37467 }
37468 else
37469 {
37470 ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[q].script, q & 0xFFF);
37471 data.doscript = 0;
37472 }
37473 }
37474 else if(data.doscript==4) //Item set itself false, kill script and clear data here.
37475 {
37476 data.doscript = 0;
37477 }
37478 if(!data.doscript) //Item script ended. Clear the data, if any remains.
37479 {
37480 data.ref.Clear();
37481 data.initialized = false;
37482 data.waitdraw = false;
37483 FFScript::deallocateAllScriptOwned(ScriptType::Item, q);
37484 }
37485 }
37486 }
37487 16271246 return false;
37488 16271246 }
37489 14622023 void FFScript::npcScriptEngineOnWaitdraw()
37490 {
37491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14622023 times.
14622023 if ( FFCore.system_suspend[susptNPCSCRIPTS] ) return;
37492 14622023 guys.run_script(MODE_WAITDRAW);
37493 14622023 }
37494
37495 14160252 void FFScript::eweaponScriptEngine()
37496 {
37497
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14160252 times.
14160252 if ( FFCore.system_suspend[susptEWEAPONSCRIPTS] ) return;
37498 14160252 Ewpns.run_script(MODE_NORMAL);
37499 14160252 }
37500
37501 14622023 void FFScript::lweaponScriptEngineOnWaitdraw()
37502 {
37503
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14622023 times.
14622023 if ( FFCore.system_suspend[susptLWEAPONSCRIPTS] ) return;
37504 14622023 Lwpns.run_script(MODE_WAITDRAW);
37505 14622023 }
37506
37507 14649732 void FFScript::eweaponScriptEngineOnWaitdraw()
37508 {
37509
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 14649722 times.
14649732 if ( FFCore.system_suspend[susptEWEAPONSCRIPTS] ) return;
37510 14649722 Ewpns.run_script(MODE_WAITDRAW);
37511 14649732 }
37512
37513 14162878 void FFScript::itemSpriteScriptEngine()
37514 {
37515
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14162878 times.
14162878 if ( FFCore.system_suspend[susptITEMSPRITESCRIPTS] ) return;
37516 14162878 items.run_script(MODE_NORMAL);
37517 14162878 }
37518
37519 14652250 void FFScript::itemSpriteScriptEngineOnWaitdraw()
37520 {
37521
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14652250 times.
14652250 if ( FFCore.system_suspend[susptITEMSPRITESCRIPTS] ) return;
37522 14652250 items.run_script(MODE_WAITDRAW);
37523 14652250 }
37524
37525
37526 15 int32_t FFScript::getTime(int32_t type)
37527 {
37528 //struct tm *tm_struct = localtime(time(NULL));
37529 struct tm * tm_struct;
37530 time_t sysRTC;
37531 15 time (&sysRTC);
37532 15 tm_struct = localtime (&sysRTC);
37533 15 int32_t rval = -1;
37534
37535
5/10
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
15 switch(type)
37536 {
37537 case curyear:
37538 {
37539 //Year format starts at 1900, yeat
37540 //A raw read of '2018' would be '118', so we add 1900 to it to derive the actual year.
37541 3 rval = tm_struct->tm_year + 1900; break;
37542
37543 }
37544 case curmonth:
37545 {
37546 //Months start at 0, but we want 1->12
37547 rval = tm_struct->tm_mon +1; break;
37548 }
37549 case curday_month:
37550 {
37551 rval = tm_struct->tm_mday; break;
37552 }
37553 case curday_week:
37554 {
37555 //It seems that weekdays are a value range of 1 to 7.
37556 rval = tm_struct->tm_wday; break;
37557 }
37558 case curhour:
37559 {
37560 3 rval = tm_struct->tm_hour; break;
37561 }
37562 case curminute:
37563 {
37564 3 rval = tm_struct->tm_min; break;
37565 }
37566 case cursecond:
37567 {
37568 3 rval = tm_struct->tm_sec; break;
37569 }
37570 case curdayyear:
37571 {
37572 //The day (n/365) out of the entire year.
37573 3 rval = tm_struct->tm_yday; break;
37574 }
37575 case curDST:
37576 {
37577 //Returns if the user is in a Time Zone with Daylight TIme of some sort.
37578 //View the time.h docs for the actual values of this struct element.
37579 rval = tm_struct->tm_isdst;; break;
37580 }
37581 default:
37582 {
37583 al_trace("Invalid category passed to GetSystemTime(%d)\n",type);
37584 rval = -1; break;
37585 }
37586
37587 }
37588 15 return rval;
37589 }
37590
37591 8 void FFScript::do_lweapon_delete()
37592 {
37593
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(0!=(s=checkLWpn(ri->lwpn)))
37594 {
37595
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(s==Hero.lift_wpn)
37596 {
37597 delete s;
37598 Hero.lift_wpn = nullptr;
37599 }
37600 8 else Lwpns.del(s);
37601 8 }
37602 8 }
37603
37604 46 void FFScript::do_eweapon_delete()
37605 {
37606
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if(0!=(s=checkEWpn(ri->ewpn)))
37607 {
37608 46 Ewpns.del(s);
37609 46 }
37610 46 }
37611
37612 1094 void FFScript::updateIncludePaths()
37613 {
37614 1094 includePaths.clear();
37615 1094 int32_t pos = 0;
37616
2/2
✓ Branch 0 taken 3774 times.
✓ Branch 1 taken 1094 times.
4868 for ( int32_t q = 0; includePathString[pos]; ++q )
37617 {
37618 3774 int32_t dest = 0;
37619 3774 char buf[2048] = {0};
37620
4/4
✓ Branch 0 taken 3692 times.
✓ Branch 1 taken 76604 times.
✓ Branch 2 taken 76522 times.
✓ Branch 3 taken 3774 times.
80296 while(includePathString[pos] != ';' && includePathString[pos])
37621 {
37622 76522 buf[dest] = includePathString[pos];
37623 76522 ++pos;
37624 76522 ++dest;
37625 }
37626 3774 ++pos;
37627
1/2
✓ Branch 0 taken 3774 times.
✗ Branch 1 not taken.
3774 std::string str(buf);
37628
1/2
✓ Branch 0 taken 3774 times.
✗ Branch 1 not taken.
3774 includePaths.push_back(str);
37629 3774 }
37630 1094 }
37631
37632 1094 void FFScript::initIncludePaths()
37633 {
37634 1094 memset(includePathString,0,sizeof(includePathString));
37635 1094 FILE* f = fopen("includepaths.txt", "r");
37636
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 1012 times.
1094 if(f)
37637 {
37638 82 int32_t pos = 0;
37639 int32_t c;
37640 82 do
37641 {
37642 52972 c = fgetc(f);
37643
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 52890 times.
52972 if(c!=EOF)
37644 52890 includePathString[pos++] = c;
37645
2/2
✓ Branch 0 taken 52890 times.
✓ Branch 1 taken 82 times.
105944 }
37646
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 52890 times.
52972 while(c!=EOF && pos<MAX_INCLUDE_PATH_CHARS);
37647
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if(pos<MAX_INCLUDE_PATH_CHARS)
37648 82 includePathString[pos] = '\0';
37649 82 includePathString[MAX_INCLUDE_PATH_CHARS-1] = '\0';
37650 82 fclose(f);
37651 82 }
37652 1012 else strcpy(includePathString, "include/;headers/;scripts/;");
37653 1094 al_trace("Full path string is: ");
37654 1094 safe_al_trace(includePathString);
37655 1094 al_trace("\n");
37656 1094 updateIncludePaths();
37657
37658
2/2
✓ Branch 0 taken 3774 times.
✓ Branch 1 taken 1094 times.
4868 for ( size_t q = 0; q < includePaths.size(); ++q )
37659 {
37660 3774 al_trace("Include path %zu: ",q);
37661 3774 safe_al_trace(includePaths.at(q));
37662 3774 al_trace("\n");
37663 3774 }
37664 1094 }
37665
37666 10 bool FFScript::checkExtension(std::string &filename, const std::string &extension)
37667 //inline bool checkExtension(std::string filename, std::string extension)
37668 {
37669 10 int32_t dot = filename.find_last_of(".");
37670
3/10
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
10 std::string exten = (dot == std::string::npos ? "" : filename.substr(dot, filename.length() - dot));
37671 10 return exten == extension;
37672 10 }
37673
37674
37675 void FFScript::do_loadgamestructs(const bool v, const bool v2)
37676 {
37677 int32_t arrayptr = SH::get_arg(sarg1, v) / 10000;
37678 int32_t section_id = SH::get_arg(sarg2, v2) / 10000;
37679 //Bitwise OR sections together
37680 string strA;
37681 ArrayH::getString(arrayptr, strA, 256);
37682 int32_t temp_sram_flags = section_id; int32_t sram_version = 0;
37683
37684 if ( FFCore.checkExtension(strA, ".zcsram") )
37685 {
37686 PACKFILE *f = pack_fopen_password(strA.c_str(),F_READ, "");
37687 if (f)
37688 {
37689 p_igetl(&sram_version,f);
37690 p_igetl(&section_id,f);
37691 if ( sram_version > SRAM_VERSION ) //file version is greater than programme current version.
37692 {
37693 Z_scripterrlog("SRAM Version is from a version of ZC newer than the running version and cannot be loaded.\n");
37694 return;
37695 }
37696 if ( section_id != temp_sram_flags )
37697 {
37698 Z_scripterrlog("Reading an SRAM file with a section flag mismatch!\nThe file section flags are (%d) and the specified flagset is (%d).\nThis may cause errors!\n", section_id, temp_sram_flags);
37699 }
37700
37701 if ( !section_id || section_id&svGUYS ) FFCore.read_enemies(f,sram_version);
37702 if ( !section_id || section_id&svITEMS )FFCore.read_items(f,sram_version);
37703 if ( !section_id || section_id&svWEAPONS ) FFCore.read_weaponsprtites(f,sram_version);
37704 if ( !section_id || section_id&svCOMBOS )
37705 {
37706 reset_all_combo_animations();
37707 FFCore.read_combos(f,sram_version);
37708 }
37709 if ( !section_id || section_id&svDMAPS ) FFCore.read_dmaps(f,sram_version);
37710 if ( !section_id || section_id&svMAPSCR ) FFCore.read_mapscreens(f,sram_version);
37711 pack_fclose(f);
37712
37713 set_register(sarg1, 10000);
37714 }
37715 else
37716 {
37717 Z_scripterrlog("FFCore.do_loadgamestructs could not read packfile!");
37718 set_register(sarg1, -10000);
37719 }
37720 }
37721 else
37722 {
37723 Z_scripterrlog("Tried to read a .zcsram file, but the file lacked the ..zcsram extension!\n");
37724 set_register(sarg1, -20000);
37725
37726 }
37727 }
37728
37729 110 void FFScript::do_savegamestructs(const bool v, const bool v2)
37730 {
37731 110 int32_t arrayptr = SH::get_arg(sarg1, v) / 10000;
37732 110 int32_t section_id = SH::get_arg(sarg2, v2) / 10000;
37733 //Bitwise OR sections together
37734 110 string strA;
37735
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 100 times.
110 ArrayH::getString(arrayptr, strA, 256);
37736 10 int32_t cycles = 0;
37737
37738
3/6
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 if ( FFCore.checkExtension(strA, ".zcsram") )
37739 {
37740
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 PACKFILE *f = pack_fopen_password(strA.c_str(),F_WRITE, "");
37741
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (f)
37742 {
37743
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 p_iputl(SRAM_VERSION,f);
37744
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 p_iputl(section_id,f);
37745
37746
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
10 if ( !section_id || section_id&svGUYS ) FFCore.write_enemies(f,SRAM_VERSION);
37747 if ( !section_id || section_id&svITEMS ) FFCore.write_items(f,SRAM_VERSION);
37748 if ( !section_id || section_id&svWEAPONS ) FFCore.write_weaponsprtites(f,SRAM_VERSION);
37749 if ( !section_id || section_id&svCOMBOS )
37750 {
37751
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 reset_all_combo_animations();
37752 FFCore.write_combos(f,SRAM_VERSION);
37753 }
37754 if ( !section_id || section_id&svDMAPS ) FFCore.write_dmaps(f,SRAM_VERSION);
37755 if ( !section_id || section_id&svMAPSCR ) FFCore.write_mapscreens(f,SRAM_VERSION);
37756
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 pack_fclose(f);
37757
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 set_register(sarg1, 10000);
37758 10 }
37759 else
37760 {
37761 Z_scripterrlog("FFCore.do_loadgamestructs could not read packfile!");
37762 set_register(sarg1, -10000);
37763 }
37764 10 }
37765 else
37766 {
37767 Z_scripterrlog("Tried to write a .zcsram file, but the file lacked the ..zcsram extension!\n");
37768 set_register(sarg1, -20000);
37769 }
37770 210 }
37771
37772 2541 void FFScript::do_strcmp()
37773 {
37774 2541 int32_t arrayptr_a = ri->d[rINDEX]/10000; //get_register(sarg1) / 10000 ?
37775 2541 int32_t arrayptr_b = ri->d[rINDEX2]/10000; //get_register(sarg2) / 10000?
37776 2541 string strA;
37777 2541 string strB;
37778
1/2
✓ Branch 0 taken 2541 times.
✗ Branch 1 not taken.
2541 ArrayH::getString(arrayptr_a, strA);
37779
1/2
✓ Branch 0 taken 2541 times.
✗ Branch 1 not taken.
2541 ArrayH::getString(arrayptr_b, strB);
37780
1/2
✓ Branch 0 taken 2541 times.
✗ Branch 1 not taken.
2541 set_register(sarg1, (strcmp(strA.c_str(), strB.c_str()) * 10000));
37781 2541 }
37782
37783 void FFScript::do_stricmp()
37784 {
37785 int32_t arrayptr_a = ri->d[rINDEX]/10000; //get_register(sarg1) / 10000? Index and Index2 are intentional.
37786 int32_t arrayptr_b = ri->d[rINDEX2]/10000; //get_register(sarg2) / 10000?
37787 string strA;
37788 string strB;
37789 ArrayH::getString(arrayptr_a, strA);
37790 ArrayH::getString(arrayptr_b, strB);
37791 set_register(sarg1, (stricmp(strA.c_str(), strB.c_str()) * 10000));
37792 }
37793
37794 1 void FFScript::do_LowerToUpper(const bool v)
37795 {
37796 1 int32_t arrayptr_a = get_register(sarg1) / 10000;
37797 1 string strA;
37798
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ArrayH::getString(arrayptr_a, strA);
37799
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
6 for (char& c : strA)
37800 5 c = std::toupper(c);
37801
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ArrayH::setArray(arrayptr_a, strA);
37802
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 set_register(sarg1, 10000); // used to return 0 if string was empty.
37803 1 }
37804
37805 void FFScript::do_UpperToLower(const bool v)
37806 {
37807 int32_t arrayptr_a = get_register(sarg1) / 10000;
37808 string strA;
37809 ArrayH::getString(arrayptr_a, strA);
37810 for (char& c : strA)
37811 c = std::tolower(c);
37812 ArrayH::setArray(arrayptr_a, strA);
37813 set_register(sarg1, 10000); // used to return 0 if string was empty.
37814 }
37815
37816 void FFScript::do_getnpcscript()
37817 {
37818 do_get_script_index_by_name(name_to_slot_index_npcmap);
37819 }
37820
37821 void FFScript::do_getcomboscript()
37822 {
37823 do_get_script_index_by_name(name_to_slot_index_comboscriptmap);
37824 }
37825
37826 137106 void FFScript::do_getgenericscript()
37827 {
37828 137106 do_get_script_index_by_name(name_to_slot_index_genericmap);
37829 137106 }
37830
37831 1707 void FFScript::do_getlweaponscript()
37832 {
37833 1707 do_get_script_index_by_name(name_to_slot_index_lwpnmap);
37834 1707 }
37835 1664 void FFScript::do_geteweaponscript()
37836 {
37837 1664 do_get_script_index_by_name(name_to_slot_index_ewpnmap);
37838 1664 }
37839 void FFScript::do_getheroscript()
37840 {
37841 do_get_script_index_by_name(name_to_slot_index_playermap);
37842 }
37843 void FFScript::do_getglobalscript()
37844 {
37845 do_get_script_index_by_name(name_to_slot_index_globalmap);
37846 }
37847 105 void FFScript::do_getdmapscript()
37848 {
37849 105 do_get_script_index_by_name(name_to_slot_index_dmapmap);
37850 105 }
37851 void FFScript::do_getscreenscript()
37852 {
37853 do_get_script_index_by_name(name_to_slot_index_screenmap);
37854 }
37855 31 void FFScript::do_getitemspritescript()
37856 {
37857 31 do_get_script_index_by_name(name_to_slot_index_itemspritemap);
37858 31 }
37859 //Not assigned to slots at present. If they ever are, then this would get the id of any script (any type) by name. -Z
37860 void FFScript::do_getuntypedscript()
37861 {
37862 set_register(sarg1, 0);
37863 }
37864 void FFScript::do_getsubscreenscript()
37865 {
37866 do_get_script_index_by_name(name_to_slot_index_subscreenmap);
37867 }
37868 void FFScript::do_getnpcbyname()
37869 {
37870 int32_t arrayptr = get_register(sarg1) / 10000;
37871 string the_string;
37872 int32_t num = -1;
37873 ArrayH::getString(arrayptr, the_string, 256); //What is the max length of a script identifier?
37874
37875 for(int32_t q = 0; q < MAXNPCS; q++)
37876 {
37877 if(!(strcmp(the_string.c_str(), guy_string[q])))
37878 {
37879 num = q;
37880 break;
37881 }
37882 }
37883 set_register(sarg1, (num * 10000));
37884 }
37885 void FFScript::do_getitembyname()
37886 {
37887 int32_t arrayptr = get_register(sarg1) / 10000;
37888 string the_string;
37889 int32_t num = -1;
37890 ArrayH::getString(arrayptr, the_string, 256); //What is the max length of a script identifier?
37891
37892 for(int32_t q = 0; q < MAXNPCS; q++)
37893 {
37894 if(!(strcmp(the_string.c_str(), item_string[q])))
37895 {
37896 num = q;
37897 break;
37898 }
37899 }
37900 set_register(sarg1, (num * 10000));
37901 }
37902 void FFScript::do_getcombobyname()
37903 {
37904 int32_t arrayptr = get_register(sarg1) / 10000;
37905 string the_string;
37906 int32_t num = -1;
37907 ArrayH::getString(arrayptr, the_string, 256);
37908
37909 if (!the_string.empty())
37910 {
37911 for(int32_t q = 0; q < MAXCOMBOS; q++)
37912 {
37913 if (the_string == combobuf[q].label)
37914 {
37915 num = q;
37916 break;
37917 }
37918 }
37919 }
37920 set_register(sarg1, (num * 10000));
37921 }
37922 void FFScript::do_getdmapbyname()
37923 {
37924 int32_t arrayptr = get_register(sarg1) / 10000;
37925 string the_string;
37926 int32_t num = -1;
37927 ArrayH::getString(arrayptr, the_string, 256); //What is the max length of a script identifier?
37928
37929 for(int32_t q = 0; q < MAXDMAPS; q++)
37930 {
37931 if(!(strcmp(the_string.c_str(), DMaps[q].name)))
37932 {
37933 num = q;
37934 break;
37935 }
37936 }
37937 set_register(sarg1, (num * 10000));
37938 }
37939
37940 ////////////////////////
37941 /// String Utilities ///
37942 ////////////////////////
37943 void FFScript::do_ConvertCase(const bool v)
37944 {
37945 int32_t arrayptr_a = get_register(sarg1) / 10000;
37946 string strA;
37947 ArrayH::getString(arrayptr_a, strA);
37948 for (char& c : strA)
37949 {
37950 if (c < 'a')
37951 c += 32 * (c >= 'A' && c <= 'Z');
37952 else
37953 c -= 32 * (c >= 'a' && c <= 'z');
37954 }
37955 ArrayH::setArray(arrayptr_a, strA);
37956 set_register(sarg1, (10000)); // used to return 0 if string was empty.
37957 }
37958
37959 void FFScript::do_xlen(const bool v)
37960 {
37961 //not implemented, xlen not found
37962 int32_t arrayptr = (SH::get_arg(sarg2, v) / 10000);
37963 string str;
37964 ArrayH::getString(arrayptr, str);
37965 //set_register(sarg1, (xlen(str.c_str()) * 10000));
37966 }
37967
37968 void FFScript::do_xtoi(const bool v)
37969 {
37970 int32_t arrayptr = (SH::get_arg(sarg2, v) / 10000);
37971 string str;
37972 ArrayH::getString(arrayptr, str);
37973 double val = zc_xtoi(const_cast<char*>(str.c_str()));
37974 set_register(sarg1, (int32_t)(val) * 10000);
37975 }
37976 void FFScript::do_xtoi2()
37977 {
37978 int32_t arrayptr_a = ri->d[rINDEX]/10000; //get_register(sarg1) / 10000? Index and Index2 are intentional.
37979 string strA;
37980 ArrayH::getString(arrayptr_a, strA);
37981 set_register(sarg1, (zc_xtoi(strA.c_str()) * 10000));
37982 }
37983
37984 // Calculates log2 of number.
37985 double FFScript::Log2( double n )
37986 {
37987 // log(n)/log(2) is log2.
37988 return log( (double)n ) / log( (double)2 );
37989 }
37990
37991 //xtoa, convert hex number to hex ascii
37992 14 void FFScript::do_xtoa()
37993 {
37994
37995 14 int32_t arrayptr_a = get_register(sarg1) / 10000;
37996 14 int32_t number = get_register(sarg2) / 10000;//ri->d[rEXP2]/10000; //why are you not in sarg2?!!
37997
37998
37999
38000 14 bool isneg = false;
38001
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if ( number < 0 )
38002 {
38003 isneg = true;
38004 number *= -1;
38005 }
38006 14 double num = number;
38007
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 int32_t digits = num ? floor(FFCore.LogToBase(num, 16) + 1) : 1;
38008
38009
38010 14 int32_t pos = 0;
38011 14 string strA;
38012
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(number == 0) //Needs to precede str.resize(digits+3) as if the number is <= 0 then this breaks.
38013 {
38014 strA.resize(3);
38015 strA[pos+2] = '0';
38016 if(ArrayH::setArray(arrayptr_a, strA) == SH::_Overflow)
38017 {
38018 Z_scripterrlog("Dest string supplied to 'itoa()' not large enough\n");
38019 set_register(sarg1, 0);
38020 }
38021 else set_register(sarg1, 30000); //returns the pointer to the dest
38022 return;
38023 }
38024 14 int32_t ret = 0;
38025
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 strA.resize(digits+3+(isneg?1:0));
38026 //num = Floor(Abs(num));
38027
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if ( isneg )
38028 {
38029 strA[pos] = '-';
38030 strA[pos+1] = '0';
38031 strA[pos+2] = 'x';
38032 ret = 3;
38033 }
38034 else
38035 {
38036
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 strA[pos] = '0';
38037
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 strA[pos+1] = 'x';
38038 14 ret = 2;
38039 }
38040
38041 14 int32_t alphaoffset = 'A' - 0xA;
38042
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 24 times.
38 for(int32_t i = 0; i < digits; ++i)
38043 {
38044
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 int32_t coeff = ((int32_t)floor((double)(((double)number) / pow((float)0x10, digits - i - 1))) % 0x10);
38045
3/4
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 strA[pos + ret + i] = coeff < 0xA ? coeff + '0' : coeff + alphaoffset;
38046 24 }
38047
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
14 if(ArrayH::setArray(arrayptr_a, strA) == SH::_Overflow)
38048 {
38049 Z_scripterrlog("Dest string supplied to 'xtoa()' not large enough\n");
38050 set_register(sarg1, 0);
38051 }
38052 //set_register(sarg1, (strcat((char)strA.c_str(), strB.c_str()) * 10000));
38053
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 else set_register(sarg1, (ret + digits -(isneg?1:0))*10000); //don't count the - sign as a digit
38054
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 }
38055
38056 void FFScript::do_ilen(const bool v)
38057 {
38058 int32_t arrayptr = (SH::get_arg(sarg2, v) / 10000);
38059 string str;
38060 ArrayH::getString(arrayptr, str);
38061 set_register(sarg1, (FFCore.ilen((char*)str.c_str()) * 10000));
38062 }
38063
38064 //! Note atoi2 (atoi(str, len) can be accompished with str.resize after getString.
38065 void FFScript::do_atoi(const bool v)
38066 {
38067 int32_t arrayptr = (SH::get_arg(sarg2, v) / 10000);
38068 string str;
38069 ArrayH::getString(arrayptr, str);
38070 set_register(sarg1, (atoi(str.c_str()) * 10000));
38071 }
38072 void FFScript::do_atol(const bool v)
38073 {
38074 int32_t arrayptr = (SH::get_arg(sarg2, v) / 10000);
38075 string str;
38076 ArrayH::getString(arrayptr, str);
38077 set_register(sarg1, (atoi(str.c_str())));
38078 }
38079
38080 void FFScript::do_strstr()
38081 {
38082
38083 int32_t arrayptr_a = ri->d[rINDEX]/10000; //get_register(sarg1) / 10000? Index and Index2 are intentional.
38084 int32_t arrayptr_b = ri->d[rINDEX2]/10000; //get_register(sarg2) / 10000?
38085 string strA;
38086 string strB;
38087 ArrayH::getString(arrayptr_a, strA);
38088 ArrayH::getString(arrayptr_b, strB);
38089 if ( strA.size() < 1 )
38090 {
38091 Z_scripterrlog("String passed to strstr() is too small. Size is: %d \n", strA.size());
38092 set_register(sarg1,-10000);
38093 return;
38094 }
38095 set_register(sarg1, (strA.find(strB) * 10000));
38096 }
38097
38098 935 void FFScript::do_strcat()
38099 {
38100
38101 935 int32_t arrayptr_a = ri->d[rINDEX]/10000; //get_register(sarg1) / 10000? Index and Index2 are intentional.
38102 935 int32_t arrayptr_b = ri->d[rINDEX2]/10000; //get_register(sarg2) / 10000?
38103 935 string strA;
38104 935 string strB;
38105
1/2
✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
935 ArrayH::getString(arrayptr_a, strA);
38106
1/2
✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
935 ArrayH::getString(arrayptr_b, strB);
38107 //char str_c[2048];
38108 //strcpy(str_c, strA.c_str());
38109
1/2
✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
935 string strC = strA + strB;
38110
2/4
✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 935 times.
935 if(ArrayH::setArray(arrayptr_a, strC) == SH::_Overflow)
38111 {
38112 Z_scripterrlog("Dest string supplied to 'strcat()' not large enough\n");
38113 set_register(sarg1, 0);
38114 }
38115 //set_register(sarg1, (strcat((char)strA.c_str(), strB.c_str()) * 10000));
38116
1/2
✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
935 else set_register(sarg1, arrayptr_a); //returns the pointer to the dest
38117 935 }
38118 void FFScript::do_strspn()
38119 {
38120
38121 int32_t arrayptr_a = ri->d[rINDEX]/10000; //get_register(sarg1) / 10000? Index and Index2 are intentional.
38122 int32_t arrayptr_b = ri->d[rINDEX2]/10000; //get_register(sarg2) / 10000?
38123 string strA;
38124 string strB;
38125 ArrayH::getString(arrayptr_a, strA);
38126 ArrayH::getString(arrayptr_b, strB);
38127 set_register(sarg1, (strspn(strA.c_str(), strB.c_str()) * 10000));
38128 }
38129
38130 void FFScript::do_strcspn()
38131 {
38132
38133 int32_t arrayptr_a = ri->d[rINDEX]/10000; //get_register(sarg1) / 10000? Index and Index2 are intentional.
38134 int32_t arrayptr_b = ri->d[rINDEX2]/10000;
38135 string strA;
38136 string strB;
38137 ArrayH::getString(arrayptr_a, strA);
38138 ArrayH::getString(arrayptr_b, strB);
38139 set_register(sarg1, (strcspn(strA.c_str(), strB.c_str()) * 10000));
38140 }
38141
38142 void FFScript::do_strchr()
38143 {
38144
38145 int32_t arrayptr_a = ri->d[rINDEX]/10000; //get_register(sarg1) / 10000? Index and Index2 are intentional.
38146 char chr_to_find = (ri->d[rINDEX2]/10000);
38147 string strA;
38148 ArrayH::getString(arrayptr_a, strA);
38149 if ( strA.size() < 1 )
38150 {
38151 Z_scripterrlog("String passed to strchr() is too small. Size is: %d \n", strA.size());
38152 set_register(sarg1,-10000);
38153 return;
38154 }
38155
38156 set_register(sarg1,strA.find_first_of(chr_to_find)*10000);
38157 }
38158 void FFScript::do_strrchr()
38159 {
38160 int32_t arrayptr_a = ri->d[rINDEX]/10000; //get_register(sarg1) / 10000? Index and Index2 are intentional.
38161 char chr_to_find = (ri->d[rINDEX2]/10000);
38162 string strA;
38163 ArrayH::getString(arrayptr_a, strA);
38164 if ( strA.size() < 1 )
38165 {
38166 Z_scripterrlog("String passed to strrchr() is too small. Size is: %d \n", strA.size());
38167 set_register(sarg1,-10000);
38168 return;
38169 }
38170 set_register(sarg1,strA.find_last_of(chr_to_find)*10000);
38171 }
38172
38173 void FFScript::do_remchr2()
38174 {
38175 //Not implemented, remchr not found
38176 //not part of any standard library
38177 int32_t arrayptr_a = ri->d[rINDEX]/10000; //get_register(sarg1) / 10000? Index and Index2 are intentional.
38178 string strA;
38179 ArrayH::getString(arrayptr_a, strA);
38180 //set_register(sarg1, (remchr(strA.c_str(), (ri->d[rINDEX2]/10000)) * 10000));
38181 }
38182 //Bookmark
38183 void FFScript::do_atoi2()
38184 {
38185 //not implemented; atoi does not take 2 params
38186 int32_t arrayptr_a = ri->d[rINDEX]/10000;
38187 string strA;
38188 ArrayH::getString(arrayptr_a, strA);
38189 //set_register(sarg1, (atoi(strA.c_str(), (ri->d[rINDEX2]/10000)) * 10000));
38190 }
38191 void FFScript::do_ilen2()
38192 {
38193 //not implemented, ilen not found
38194 int32_t arrayptr_a = ri->d[rINDEX]/10000;
38195 string strA;
38196 ArrayH::getString(arrayptr_a, strA);
38197 //set_register(sarg1, (ilen(strA.c_str(), (ri->d[rINDEX2]/10000)) * 10000));
38198 }
38199 void FFScript::do_xlen2()
38200 {
38201 //not implemented, xlen not found
38202 int32_t arrayptr_a = ri->d[rINDEX]/10000;
38203 string strA;
38204 ArrayH::getString(arrayptr_a, strA);
38205 //set_register(sarg1, (xlen(strA.c_str(), (ri->d[rINDEX2]/10000)) * 10000));
38206 }
38207
38208 4797 void FFScript::do_itoa()
38209 {
38210 4797 int32_t arrayptr_a = get_register(sarg1) / 10000;
38211 4797 int32_t number = get_register(sarg2) / 10000;
38212
38213 char buf[16];
38214 4797 zc_itoa(number, buf, 10);
38215 4797 int32_t ret = ::strlen(buf) * 10000L;
38216
1/2
✓ Branch 0 taken 4797 times.
✗ Branch 1 not taken.
4797 string strA(buf);
38217
38218
2/4
✓ Branch 0 taken 4797 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4797 times.
4797 if(ArrayH::setArray(arrayptr_a, strA) == SH::_Overflow)
38219 {
38220 Z_scripterrlog("Dest string supplied to 'itoa()' not large enough\n");
38221 set_register(sarg1, -1);
38222 }
38223
1/2
✓ Branch 0 taken 4797 times.
✗ Branch 1 not taken.
4797 else set_register(sarg1, ret); //returns the number of digits used
38224 4797 }
38225
38226 56 void FFScript::do_itoacat()
38227 {
38228 56 int32_t arrayptr_a = get_register(sarg1) / 10000;
38229 56 int32_t number = get_register(sarg2) / 10000;
38230
38231 56 double num = number;
38232 56 int32_t digits = FFCore.numDigits(number); //int32_t(log10(temp) * 10000.0)
38233 56 int32_t pos = 0;
38234 56 int32_t ret = 0;
38235 56 string strA;
38236 56 string strB;
38237
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 strB.resize(digits);
38238
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 ArrayH::getString(arrayptr_a, strA);
38239
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 if(num < 0)
38240 {
38241 strB.resize(digits+1);
38242 strB[pos] = '-';
38243 ++ret;
38244 num = -num;
38245 }
38246
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 else if(num == 0)
38247 {
38248 strB[pos] = '0';
38249 string strC = strA + strB;
38250 if(ArrayH::setArray(arrayptr_a, strC) == SH::_Overflow)
38251 {
38252 Z_scripterrlog("Dest string supplied to 'itoacat()' not large enough\n");
38253 set_register(sarg1, 0);
38254 }
38255 else set_register(sarg1, arrayptr_a); //returns the pointer to the dest
38256 return;
38257 }
38258
38259
38260
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 84 times.
140 for(int32_t i = 0; i < digits; ++i)
38261
2/4
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 84 times.
✗ Branch 3 not taken.
84 strB[pos + ret + i] = ((int32_t)floor((double)(num / pow((float)10, digits - i - 1))) % 10) + '0';
38262
38263
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 string strC = strA + strB;
38264
2/4
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 56 times.
56 if(ArrayH::setArray(arrayptr_a, strC) == SH::_Overflow)
38265 {
38266 Z_scripterrlog("Dest string supplied to 'itoacat()' not large enough\n");
38267 set_register(sarg1, 0);
38268 }
38269 //set_register(sarg1, (strcat((char)strB.c_str(), strB.c_str()) * 10000));
38270
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 else set_register(sarg1, arrayptr_a); //returns the pointer to the dest
38271
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 }
38272
38273 2925 void FFScript::do_strcpy(const bool a, const bool b)
38274 {
38275 2925 int32_t arrayptr_b = SH::get_arg(sarg1, a) / 10000;
38276 2925 int32_t arrayptr_a = SH::get_arg(sarg2, b) / 10000;
38277
38278 2925 string strA;
38279
38280
1/2
✓ Branch 0 taken 2925 times.
✗ Branch 1 not taken.
2925 ArrayH::getString(arrayptr_a, strA);
38281
38282
2/4
✓ Branch 0 taken 2925 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2925 times.
2925 if(ArrayH::setArray(arrayptr_b, strA) == SH::_Overflow)
38283 Z_scripterrlog("Dest string supplied to 'strcpy()' not large enough\n");
38284 2925 }
38285 1 void FFScript::do_arraycpy(const bool a, const bool b)
38286 {
38287 1 int32_t arrayptr_dest = SH::get_arg(sarg1, a) / 10000;
38288 1 int32_t arrayptr_src = SH::get_arg(sarg2, b) / 10000;
38289 1 ArrayH::copyValues(arrayptr_dest, arrayptr_src);
38290 1 }
38291 6048 void FFScript::do_strlen(const bool v)
38292 {
38293 6048 int32_t arrayptr = (SH::get_arg(sarg2, v) / 10000);
38294 6048 string str;
38295
1/2
✓ Branch 0 taken 6048 times.
✗ Branch 1 not taken.
6048 ArrayH::getString(arrayptr, str);
38296
1/2
✓ Branch 0 taken 6048 times.
✗ Branch 1 not taken.
6048 set_register(sarg1, (str.length() * 10000));
38297 6048 }
38298
38299 void FFScript::do_strncmp()
38300 {
38301 int32_t arrayptr_a = ri->d[rINDEX]/10000;
38302 int32_t arrayptr_b = ri->d[rEXP2]/10000;
38303 int32_t len = ri->d[rEXP1]/10000;
38304 string strA;
38305 string strB;
38306 ArrayH::getString(arrayptr_a, strA);
38307 ArrayH::getString(arrayptr_b, strB);
38308 set_register(sarg1, (strncmp(strA.c_str(), strB.c_str(), len) * 10000));
38309 }
38310
38311 void FFScript::do_strnicmp()
38312 {
38313 int32_t arrayptr_a = ri->d[rINDEX]/10000;
38314 int32_t arrayptr_b = ri->d[rEXP2]/10000;
38315 int32_t len = ri->d[rEXP1]/10000;
38316 string strA;
38317 string strB;
38318 ArrayH::getString(arrayptr_a, strA);
38319 ArrayH::getString(arrayptr_b, strB);
38320 set_register(sarg1, (ustrnicmp(strA.c_str(), strB.c_str(), len) * 10000));
38321 }
38322
38323 /////////////////////
38324 /// MATHS HELPERS ///
38325 /////////////////////
38326
38327 //Returns the log of val to the base 10. Any value <= 0 will return 0.
38328 int32_t FFScript::Log10(double temp)
38329 {
38330 int32_t ret = 0;
38331 if(temp > 0)
38332 ret = int32_t(log10(temp) * 10000.0);
38333 else ret = 0;
38334 return ret;
38335 }
38336
38337 //Returns the number of digits in a given integer.
38338 56 int32_t FFScript::numDigits(int32_t number)
38339 {
38340 56 int32_t digits = 0;
38341
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 56 times.
140 while (number)
38342 {
38343 84 number /= 10;
38344 84 digits++;
38345 }
38346 56 return digits;
38347 }
38348
38349 // Returns the natural logarithm of val (to the base e). Any value <= 0 will return 0.
38350 28 double FFScript::ln(double temp)
38351 {
38352
38353
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 if(temp > 0)
38354 28 return (log(temp));
38355 else
38356 {
38357 return 0;
38358 }
38359 28 }
38360
38361 // Returns the logarithm of x to the given base.
38362 14 double FFScript::LogToBase(double x, double base)
38363 {
38364
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
14 if(x <= 0 || base <= 0) return 0;
38365 14 return FFCore.ln(x)/FFCore.ln(base);
38366 14 }
38367
38368 ///----------------------------------------------------------------------------------------------------//
38369 //Debugger and Logging Consoles
38370
38371 template <typename ...Params>
38372 void FFScript::ZScriptConsole(int32_t attributes,const char *format, Params&&... params)
38373 {
38374 //if ( open )
38375 {
38376 zscript_coloured_console.Create("ZQuest Classic Logging Console", 600, 200, NULL, NULL);
38377 zscript_coloured_console.cls(CConsoleLoggerEx::COLOR_BACKGROUND_BLACK);
38378 zscript_coloured_console.gotoxy(0,0);
38379 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
38380 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"ZQuest Classic Logging Console\n");
38381
38382 zscript_coloured_console.cprintf( attributes, format, std::forward<Params>(params)...);
38383 }
38384 //else
38385 //{
38386 //close
38387 // zscript_coloured_console.Close();
38388 //}
38389 }
38390
38391 416 void clearConsole()
38392 {
38393 416 zscript_coloured_console.cls(CConsoleLoggerEx::COLOR_BACKGROUND_BLACK);
38394 416 zscript_coloured_console.gotoxy(0,0);
38395
38396 416 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_RED | CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
38397 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"\n _____ ____ __ \n");
38398 416 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_RED | CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
38399 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK," /__ / / __ \\__ _____ _____/ /_\n");
38400 416 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_RED | CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
38401 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK," / / / / / / / / / _ \\/ ___/ __/\n");
38402 416 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_RED | CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
38403 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK," / /__/ /_/ / /_/ / __(__ ) /_ \n");
38404 416 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_RED | CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
38405 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK," /____/\\___\\_\\__,_/\\___/____/\\__/\n\n");
38406
38407 416 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
38408 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"ZC Console\n");
38409
38410 832 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE |CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
38411 416 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"Running: %s\n", getVersionString());
38412
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 414 times.
416 if ( FFCore.getQuestHeaderInfo(vZelda) > 0 )
38413 {
38414 414 char const* verstr = QHeader.getVerStr();
38415
2/2
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 107 times.
414 if(verstr[0])
38416 {
38417 107 auto vercmp = QHeader.compareVer();
38418 107 auto astatecmp = compare(int32_t(QHeader.getAlphaState()), getAlphaState());
38419 107 auto avercmp = compare(QHeader.getAlphaVer(), 0);
38420 107 auto timecmp = QHeader.compareDate();
38421
4/6
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 92 times.
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 15 times.
107 if(!(vercmp || astatecmp || avercmp))
38422 {
38423
3/4
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
15 if(!timecmp || !QHeader.new_version_is_nightly)
38424 30 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE |CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
38425 15 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"Quest Made in this build\n", verstr);
38426 else if(timecmp < 0)
38427 {
38428 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE |CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
38429 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"Quest Made in an earlier nightly of the same build\n", verstr);
38430 }
38431 else
38432 {
38433 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE |CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
38434 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"Quest Made in an LATER nightly of the same build!\n"
38435 "This may be unsafe to play in this version!\n", verstr);
38436 }
38437 15 }
38438 184 else zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE |CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
38439 92 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"Quest Made in: %s\n", verstr);
38440 107 }
38441 414 }
38442 416 }
38443 void FFScript::ZScriptConsole(bool open)
38444 {
38445 if ( open )
38446 {
38447 zscript_coloured_console.Create("ZC Console", 600, 200, NULL, NULL);
38448 clearConsole();
38449 console_enabled = 1;
38450 }
38451 else
38452 {
38453 zscript_coloured_console.Close();
38454 console_enabled = 0;
38455 }
38456 zc_set_config("CONSOLE","enabled",console_enabled);
38457 }
38458
38459 ///----------------------------------------------------------------------------------------------------//
38460 //Tracing
38461
38462 10317 void FFScript::do_trace(bool v)
38463 {
38464
5/14
✗ Branch 0 not taken.
✓ Branch 1 taken 10317 times.
✓ Branch 2 taken 10317 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10317 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 10317 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 10317 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
20634 bool should_replay_trace = replay_is_active() && replay_get_meta_bool("script_trace");
38465 // For now, only prevent tracing to allegro log for Web version. Some quests may expect players to
38466 // look in the logs for spoiler/secret stuff.
38467 #ifdef __EMSCRIPTEN__
38468 bool should_trace = console_enabled || should_replay_trace;
38469 if (!should_trace) return;
38470 #endif
38471
38472 10317 int32_t temp = SH::get_arg(sarg1, v);
38473
38474 char tmp[100];
38475
2/2
✓ Branch 0 taken 10311 times.
✓ Branch 1 taken 6 times.
10317 sprintf(tmp, (temp < 0 ? "%06d" : "%05d"), temp);
38476
1/2
✓ Branch 0 taken 10317 times.
✗ Branch 1 not taken.
10317 string s2(tmp);
38477
5/10
✓ Branch 0 taken 10317 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10317 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10317 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10317 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 10317 times.
✗ Branch 9 not taken.
10317 s2 = s2.substr(0, s2.size() - 4) + "." + s2.substr(s2.size() - 4, 4) + "\n";
38478
1/2
✓ Branch 0 taken 10317 times.
✗ Branch 1 not taken.
10317 TraceScriptIDs();
38479
1/2
✓ Branch 0 taken 10317 times.
✗ Branch 1 not taken.
10317 al_trace("%s", s2.c_str());
38480
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 10277 times.
10317 if (should_replay_trace)
38481
2/4
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
40 replay_step_comment("trace: " + s2);
38482
38483
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10317 times.
10317 if ( console_enabled )
38484 {
38485 zscript_coloured_console.safeprint((CConsoleLoggerEx::COLOR_WHITE |
38486 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),s2.c_str());
38487 }
38488 10317 }
38489 void FFScript::do_tracel(bool v)
38490 {
38491 int32_t temp = SH::get_arg(sarg1, v);
38492
38493 char tmp[32];
38494 sprintf(tmp, "%d\n", temp);
38495 TraceScriptIDs();
38496 al_trace("%s", tmp);
38497 if (replay_is_active() && replay_get_meta_bool("script_trace"))
38498 replay_step_comment(fmt::format("trace: {}", temp));
38499
38500 if ( console_enabled )
38501 {
38502 zscript_coloured_console.safeprint((CConsoleLoggerEx::COLOR_WHITE |
38503 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),tmp);
38504 }
38505 }
38506
38507 void FFScript::do_tracebool(const bool v)
38508 {
38509 int32_t temp = SH::get_arg(sarg1, v);
38510 TraceScriptIDs();
38511 char const* str = temp ? "true\n" : "false\n";
38512 al_trace("%s", str);
38513 if (replay_is_active() && replay_get_meta_bool("script_trace"))
38514 replay_step_comment(fmt::format("trace: {}", (bool)temp));
38515
38516 if ( console_enabled )
38517 {
38518 zscript_coloured_console.safeprint((CConsoleLoggerEx::COLOR_WHITE |
38519 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),str);
38520 }
38521 }
38522
38523 35117 void traceStr(string const& str)
38524 {
38525 35117 FFCore.TraceScriptIDs();
38526 35117 safe_al_trace(str);
38527
7/16
✗ Branch 0 not taken.
✓ Branch 1 taken 35117 times.
✓ Branch 2 taken 35117 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 35117 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 35117 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 35117 times.
✓ Branch 10 taken 1642 times.
✓ Branch 11 taken 33475 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
70234 if (replay_is_active() && replay_get_meta_bool("script_trace"))
38528
1/2
✓ Branch 0 taken 33475 times.
✗ Branch 1 not taken.
33475 replay_step_comment("trace: " + str);
38529
38530
1/2
✓ Branch 0 taken 35117 times.
✗ Branch 1 not taken.
35117 if ( console_enabled )
38531 {
38532 zscript_coloured_console.safeprint((CConsoleLoggerEx::COLOR_WHITE |
38533 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),str.c_str());
38534 }
38535 35117 }
38536
38537 1361 void FFScript::do_tracestring()
38538 {
38539 1361 int32_t arrayptr = get_register(sarg1) / 10000;
38540 1361 string str;
38541
1/2
✓ Branch 0 taken 1361 times.
✗ Branch 1 not taken.
1361 ArrayH::getString(arrayptr, str, 512);
38542
1/2
✓ Branch 0 taken 1361 times.
✗ Branch 1 not taken.
1361 str += "\0"; //In the event that the user passed an array w/o NULL, don't crash.
38543
1/2
✓ Branch 0 taken 1361 times.
✗ Branch 1 not taken.
1361 traceStr(str);
38544 1361 }
38545
38546 bool is_valid_format(char c)
38547 {
38548 switch(c)
38549 {
38550 case 'f': case 'd': case 'i': case 'p':
38551 case 'l': case 's': case 'c': case 'X':
38552 case 'x': case 'b': case 'B': case 'a':
38553 return true;
38554 }
38555 return false;
38556 }
38557 #define FORMATTER_FLAG_0FILL 0x01
38558 88336 char const* zs_formatter(char const* format, int32_t arg, int32_t mindig, dword flags)
38559 {
38560
3/4
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 88291 times.
✓ Branch 2 taken 45 times.
✗ Branch 3 not taken.
88336 static std::string ret;
38561
38562 88336 ret.clear();
38563
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 88336 times.
88336 if(format)
38564 {
38565 176672 std::string mdstr = fmt::format("%{}{}{}",(flags&FORMATTER_FLAG_0FILL)?"0":"",
38566
2/4
✓ Branch 0 taken 88336 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 88336 times.
88336 mindig, (format[0] == 'x' || format[0] == 'X') ? format[0] : 'd');
38567 88336 char const* mindigbuf = mdstr.c_str();
38568 88336 bool tempbool = false;
38569
3/12
✓ Branch 0 taken 552 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 79423 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 8361 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
88336 switch(format[0])
38570 {
38571 case 'f':
38572 tempbool = true;
38573 [[fallthrough]];
38574 case 'd':
38575
2/2
✓ Branch 0 taken 78480 times.
✓ Branch 1 taken 943 times.
80366 if(arg%10000)
38576 943 tempbool = true;
38577 [[fallthrough]];
38578 case 'i':
38579 case 'p':
38580 {
38581 79423 char argbuf[32] = {0};
38582 79423 bool neg = arg < 0;
38583
2/2
✓ Branch 0 taken 78006 times.
✓ Branch 1 taken 1417 times.
79423 if(mindig)
38584 1417 sprintf(argbuf,mindigbuf,arg / 10000);
38585
1/2
✓ Branch 0 taken 78006 times.
✗ Branch 1 not taken.
78006 else zc_itoa(arg / 10000, argbuf);
38586
38587
2/2
✓ Branch 0 taken 78480 times.
✓ Branch 1 taken 943 times.
79423 if(tempbool) //add decimal places
38588 {
38589 943 arg = abs(arg);
38590 943 auto ind = strlen(argbuf);
38591 943 argbuf[ind++] = '.';
38592
2/2
✓ Branch 0 taken 3772 times.
✓ Branch 1 taken 943 times.
4715 for(int div = 1000; div > 0; div /= 10)
38593 3772 argbuf[ind++] = '0' + (arg/div)%10;
38594
4/4
✓ Branch 0 taken 943 times.
✓ Branch 1 taken 488 times.
✓ Branch 2 taken 488 times.
✓ Branch 3 taken 943 times.
1431 for(--ind; argbuf[ind]=='0' && argbuf[ind-1]!='-'; --ind)
38595 {
38596 488 argbuf[ind] = 0;
38597 488 }
38598 943 }
38599
38600
4/4
✓ Branch 0 taken 10938 times.
✓ Branch 1 taken 68485 times.
✓ Branch 2 taken 104 times.
✓ Branch 3 taken 10834 times.
79423 if(neg && argbuf[0] != '-')
38601
1/2
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
104 ret = "-";
38602
1/2
✓ Branch 0 taken 79423 times.
✗ Branch 1 not taken.
79423 ret += argbuf;
38603 79423 return ret.c_str();
38604 }
38605 //
38606 case 'l':
38607 {
38608 char argbuf[32] = {0};
38609 if(mindig)
38610 sprintf(argbuf, mindigbuf, arg);
38611 else zc_itoa(arg, argbuf);
38612
38613 ret = argbuf;
38614 return ret.c_str();
38615 }
38616 //
38617 case 's':
38618 {
38619
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8361 times.
8361 if(mindig)
38620 Z_scripterrlog("Cannot use minimum digits flag for '%%s'\n");
38621
1/2
✓ Branch 0 taken 8361 times.
✗ Branch 1 not taken.
8361 if(arg)
38622 {
38623 8361 int32_t strptr = (arg / 10000);
38624
1/2
✓ Branch 0 taken 8361 times.
✗ Branch 1 not taken.
8361 ArrayManager am(strptr);
38625
2/4
✓ Branch 0 taken 8361 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8361 times.
8361 if(am.invalid())
38626 ret = "<INVALID STRING>";
38627
1/2
✓ Branch 0 taken 8361 times.
✗ Branch 1 not taken.
8361 else ArrayH::getString(strptr, ret, MAX_ZC_ARRAY_SIZE);
38628 8361 }
38629 else ret = "<NULL>";
38630 8361 return ret.c_str();
38631 }
38632 case 'c':
38633 {
38634
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 552 times.
552 if(mindig)
38635 Z_scripterrlog("Cannot use minimum digits flag for '%%c'\n");
38636 552 int32_t c = (arg / 10000);
38637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 552 times.
552 if ( (byte(c)) != c )
38638 {
38639 Z_scripterrlog("Illegal char value (%d) passed to sprintf as '%%c' arg\n", c);
38640 Z_scripterrlog("Value of invalid char will overflow.\n");
38641 }
38642
1/2
✓ Branch 0 taken 552 times.
✗ Branch 1 not taken.
552 ret.push_back(byte(c));
38643 552 return ret.c_str();
38644 }
38645 //
38646 case 'X':
38647 tempbool = true;
38648 [[fallthrough]];
38649 case 'x':
38650 {
38651 char argbuf[32] = {0};
38652 if(mindig)
38653 sprintf(argbuf,mindigbuf,arg / 10000);
38654 else zc_itoa( (arg/10000), argbuf, 16 ); //base 16; hex
38655
38656 for ( int32_t inx = 0; inx < 16; ++inx ) //set chosen caps
38657 {
38658 argbuf[inx] = ( tempbool ? toupper(argbuf[inx]) : tolower(argbuf[inx]) );
38659 }
38660 ret = "0x";
38661 ret += argbuf;
38662 return ret.c_str();
38663 }
38664 //
38665 case 'b': //int binary
38666 arg /= 10000;
38667 [[fallthrough]];
38668 case 'B': //long binary
38669 {
38670 char argbuf[33] = {0};
38671 int num_digits = mindig;
38672 for(int q = num_digits; q < 32; ++q)
38673 if(arg&(1<<q))
38674 num_digits = q+1;
38675 for(int q = 0; q < num_digits; ++q)
38676 {
38677 argbuf[q] = (arg&(1<<(num_digits-q-1)))
38678 ? '1' : '0';
38679 }
38680 ret = argbuf;
38681 return ret.c_str();
38682 }
38683 case 'a': //array
38684 {
38685 if(arg)
38686 {
38687 if(!is_valid_format(format[1]))
38688 {
38689 Z_scripterrlog("Format '%%a%c' is invalid!\n",format[1]);
38690 break;
38691 }
38692 ArrayManager am(arg/10000);
38693 ret = am.asString([&](int32_t val)
38694 {
38695 return zs_formatter(format+1, val, mindig, flags);
38696 }, 214748);
38697 }
38698 else ret = "{ NULL }";
38699 return ret.c_str();
38700 }
38701 default:
38702 {
38703 Z_scripterrlog("Error: '%%%c' is not a valid printf argument.\n",format[0]);
38704 return ret.c_str();
38705 }
38706 }
38707
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 88336 times.
✗ Branch 2 not taken.
88336 }
38708 Z_scripterrlog("Error: No format parameter given for zs_formatter\n");
38709 return ret.c_str();
38710 88336 }
38711
38712 64788 static int32_t zspr_varg_getter(int32_t,int32_t next_arg)
38713 {
38714 64788 return zs_vargs.at(next_arg);
38715 }
38716 23548 static int32_t zspr_stack_getter(int32_t num_args, int32_t next_arg)
38717 {
38718 23548 return SH::read_stack(((ri->sp + num_args) - 1) - next_arg);
38719 }
38720 45720 string zs_sprintf(char const* format, int32_t num_args, std::function<int32_t(int32_t,int32_t)> arg_getter)
38721 {
38722 45720 int32_t next_arg = 0;
38723 45720 bool is_old_args = get_qr(qr_OLD_PRINTF_ARGS);
38724 45720 ostringstream oss;
38725
2/2
✓ Branch 0 taken 12079 times.
✓ Branch 1 taken 121977 times.
134056 while(format[0] != '\0')
38726 {
38727 121977 int32_t arg_val = 0;
38728
2/2
✓ Branch 0 taken 88336 times.
✓ Branch 1 taken 33641 times.
121977 if(next_arg < num_args)
38729 {
38730
1/2
✓ Branch 0 taken 88336 times.
✗ Branch 1 not taken.
88336 arg_val = arg_getter(num_args,next_arg);
38731 88336 }
38732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33641 times.
33641 else if(get_qr(qr_PRINTF_NO_0FILL))
38733 {
38734 oss << format;
38735 return oss.str();
38736 }
38737 121977 char buf[256] = {0};
38738
2/2
✓ Branch 0 taken 88336 times.
✓ Branch 1 taken 457421 times.
545757 for ( int32_t q = 0; q < 256; ++q )
38739 {
38740
2/2
✓ Branch 0 taken 33641 times.
✓ Branch 1 taken 423780 times.
457421 if(format[0] == '\0') //done
38741 {
38742
1/2
✓ Branch 0 taken 33641 times.
✗ Branch 1 not taken.
33641 oss << buf;
38743
1/2
✓ Branch 0 taken 33641 times.
✗ Branch 1 not taken.
33641 return oss.str();
38744 }
38745
2/2
✓ Branch 0 taken 88966 times.
✓ Branch 1 taken 334814 times.
423780 else if(format[0] == '%')
38746 {
38747 88966 ++format;
38748 88966 int32_t min_digits = 0;
38749 88966 dword formatter_flags = 0;
38750
5/6
✓ Branch 0 taken 88336 times.
✓ Branch 1 taken 630 times.
✓ Branch 2 taken 1417 times.
✓ Branch 3 taken 86919 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1417 times.
88966 if(format[0] >= '0' && format[0] <= '9' && !is_old_args)
38751 {
38752 1417 char argbuf[4] = {0};
38753 1417 int32_t q = 0;
38754
1/2
✓ Branch 0 taken 1417 times.
✗ Branch 1 not taken.
1417 if(format[0] == '0') //Leading 0 means to 0-fill, and gets eaten
38755 1417 formatter_flags |= FORMATTER_FLAG_0FILL;
38756 else --format; //else don't eat
38757
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2834 times.
2834 while(q < 4)
38758 {
38759 2834 ++format;
38760 2834 char c = format[0];
38761
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2834 times.
2834 if(c == '\0')
38762 {
38763 Z_scripterrlog("Cannot use minimum digits flag with no argument\n");
38764 oss << buf;
38765 return oss.str();
38766 }
38767
3/4
✓ Branch 0 taken 2834 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1417 times.
✓ Branch 3 taken 1417 times.
2834 if(c >= '0' && c <= '9')
38768 1417 argbuf[q++] = c;
38769 else
38770 {
38771 1417 --format;
38772 1417 break;
38773 }
38774 }
38775 1417 ++format;
38776 1417 min_digits = atoi(argbuf);
38777
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1417 times.
1417 if(!min_digits)
38778 {
38779 Z_scripterrlog("Error formatting string: Invalid number '%s'\n", argbuf);
38780 }
38781 1417 }
38782
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 88966 times.
88966 bool bin = (format[0] == 'b' || format[0] == 'B');
38783
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 88966 times.
88966 bool hex = (format[0] == 'x' || format[0] == 'X');
38784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 88966 times.
88966 if(bin)
38785 {
38786 if(min_digits > 32)
38787 {
38788 Z_scripterrlog("Min digits argument cannot be larger than 32!"
38789 " Value will be truncated to 32.");
38790 min_digits = 32;
38791 }
38792 }
38793
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 88966 times.
88966 else if(min_digits > 10)
38794 {
38795 Z_scripterrlog("Min digits argument cannot be larger than 10!"
38796 " Value will be truncated to 10.");
38797 min_digits = 10;
38798 }
38799
38800 88966 bool tempbool = false;
38801
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 88336 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 630 times.
88966 switch( format[0] )
38802 {
38803 case 'd':
38804 case 'f':
38805 case 'i': case 'p':
38806 case 'l':
38807 case 's':
38808 case 'c':
38809 case 'x': case 'X':
38810 case 'b': case 'B':
38811 {
38812 88336 ++next_arg;
38813
3/6
✓ Branch 0 taken 88336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88336 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 88336 times.
✗ Branch 5 not taken.
88336 oss << buf << zs_formatter(format,arg_val,min_digits,formatter_flags);
38814 88336 q = 300; //break main loop
38815 88336 break;
38816 }
38817 case 'a': //array print
38818 {
38819 ++next_arg;
38820 oss << buf << zs_formatter(format,arg_val,min_digits,formatter_flags);
38821 while(format[0] == 'a')
38822 {
38823 if(is_valid_format(format[1]))
38824 ++format;
38825 else break;
38826 }
38827 q = 300; //break main loop
38828 break;
38829 }
38830 case '%':
38831 {
38832
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 630 times.
630 if(min_digits)
38833 Z_scripterrlog("Cannot use minimum digits flag for '%%%%'\n");
38834 630 buf[q] = '%';
38835 630 break;
38836 }
38837 default:
38838 {
38839 if(is_old_args)
38840 buf[q] = format[0];
38841 else
38842 {
38843 Z_scripterrlog("Error: '%%%c' is not a valid printf argument.\n",format[0]);
38844 }
38845 break;
38846 }
38847 }
38848 88966 ++format;
38849 88966 }
38850 else
38851 {
38852 334814 buf[q] = format[0];
38853 334814 ++format;
38854 }
38855
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 423780 times.
423780 if(q == 255)
38856 {
38857 oss << buf;
38858 break;
38859 }
38860 423780 }
38861 }
38862
1/2
✓ Branch 0 taken 12079 times.
✗ Branch 1 not taken.
12079 return oss.str();
38863 45720 }
38864
38865 33756 void FFScript::do_printf(const bool v, const bool varg)
38866 {
38867 int32_t num_args, format_arrayptr;
38868
2/2
✓ Branch 0 taken 33469 times.
✓ Branch 1 taken 287 times.
33756 if(varg)
38869 {
38870 33469 num_args = zs_vargs.size();
38871 33469 format_arrayptr = SH::read_stack(ri->sp) / 10000;
38872 33469 }
38873 else
38874 {
38875 287 num_args = SH::get_arg(sarg1, v) / 10000;
38876 287 format_arrayptr = SH::read_stack(ri->sp + num_args) / 10000;
38877 }
38878 33756 ArrayManager fmt_am(format_arrayptr);
38879
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33756 times.
33756 if(!fmt_am.invalid())
38880 {
38881 33756 string formatstr;
38882
1/2
✓ Branch 0 taken 33756 times.
✗ Branch 1 not taken.
33756 ArrayH::getString(format_arrayptr, formatstr, MAX_ZC_ARRAY_SIZE);
38883
38884
4/6
✓ Branch 0 taken 33469 times.
✓ Branch 1 taken 287 times.
✓ Branch 2 taken 33756 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 33756 times.
33756 traceStr(zs_sprintf(formatstr.c_str(), num_args, varg ? zspr_varg_getter : zspr_stack_getter));
38885 33756 }
38886
2/2
✓ Branch 0 taken 287 times.
✓ Branch 1 taken 33469 times.
33756 if(varg)
38887 33469 zs_vargs.clear();
38888 33756 }
38889 11964 void FFScript::do_sprintf(const bool v, const bool varg)
38890 {
38891 int32_t num_args, dest_arrayptr, format_arrayptr;
38892
2/2
✓ Branch 0 taken 319 times.
✓ Branch 1 taken 11645 times.
11964 if(varg)
38893 {
38894 319 num_args = zs_vargs.size();
38895 319 dest_arrayptr = SH::read_stack(ri->sp + 1) / 10000;
38896 319 format_arrayptr = SH::read_stack(ri->sp) / 10000;
38897 319 }
38898 else
38899 {
38900 11645 num_args = SH::get_arg(sarg1, v) / 10000;
38901 11645 dest_arrayptr = SH::read_stack(ri->sp + num_args + 1) / 10000;
38902 11645 format_arrayptr = SH::read_stack(ri->sp + num_args) / 10000;
38903 }
38904 11964 ArrayManager fmt_am(format_arrayptr);
38905 11964 ArrayManager dst_am(dest_arrayptr);
38906
2/4
✓ Branch 0 taken 11964 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11964 times.
11964 if(fmt_am.invalid() || dst_am.invalid())
38907 ri->d[rEXP1] = 0;
38908 else
38909 {
38910 11964 string formatstr;
38911
1/2
✓ Branch 0 taken 11964 times.
✗ Branch 1 not taken.
11964 ArrayH::getString(format_arrayptr, formatstr, MAX_ZC_ARRAY_SIZE);
38912
38913
3/4
✓ Branch 0 taken 319 times.
✓ Branch 1 taken 11645 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11964 times.
11964 string output = zs_sprintf(formatstr.c_str(), num_args, varg ? zspr_varg_getter : zspr_stack_getter);
38914
2/4
✓ Branch 0 taken 11964 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11964 times.
11964 if(ArrayH::setArray(dest_arrayptr, output, true) == SH::_Overflow)
38915 {
38916 Z_scripterrlog("Dest string supplied to 'sprintf()' not large enough and cannot be resized\n");
38917 ri->d[rEXP1] = ArrayH::strlen(dest_arrayptr);
38918 }
38919 11964 else ri->d[rEXP1] = output.size();
38920 11964 }
38921
2/2
✓ Branch 0 taken 11645 times.
✓ Branch 1 taken 319 times.
11964 if(varg)
38922 319 zs_vargs.clear();
38923 11964 }
38924 void FFScript::do_printfarr()
38925 {
38926 int32_t format_arrayptr = SH::read_stack(ri->sp + 1) / 10000,
38927 args_arrayptr = SH::read_stack(ri->sp + 0) / 10000;
38928 ArrayManager fmt_am(format_arrayptr);
38929 ArrayManager arg_am(args_arrayptr);
38930 if(!(fmt_am.invalid() || arg_am.invalid()))
38931 {
38932 auto num_args = arg_am.size();
38933 string formatstr;
38934 ArrayH::getString(format_arrayptr, formatstr, MAX_ZC_ARRAY_SIZE);
38935
38936 traceStr(zs_sprintf(formatstr.c_str(), num_args,
38937 [&](int32_t,int32_t next_arg)
38938 {
38939 return arg_am.get(next_arg);
38940 }));
38941 }
38942 }
38943 void FFScript::do_sprintfarr()
38944 {
38945 int32_t dest_arrayptr = SH::read_stack(ri->sp + 2) / 10000,
38946 format_arrayptr = SH::read_stack(ri->sp + 1) / 10000,
38947 args_arrayptr = SH::read_stack(ri->sp + 0) / 10000;
38948 ArrayManager fmt_am(format_arrayptr);
38949 ArrayManager arg_am(args_arrayptr);
38950 ArrayManager dst_am(dest_arrayptr);
38951 if(fmt_am.invalid() || arg_am.invalid() || dst_am.invalid())
38952 ri->d[rEXP1] = 0;
38953 else
38954 {
38955 auto num_args = arg_am.size();
38956 string formatstr;
38957 ArrayH::getString(format_arrayptr, formatstr, MAX_ZC_ARRAY_SIZE);
38958
38959 string output = zs_sprintf(formatstr.c_str(), num_args,
38960 [&](int32_t,int32_t next_arg)
38961 {
38962 return arg_am.get(next_arg);
38963 });
38964
38965 if(ArrayH::setArray(dest_arrayptr, output, true) == SH::_Overflow)
38966 {
38967 Z_scripterrlog("Dest string supplied to 'sprintfa()' not large enough and cannot be resized\n");
38968 ri->d[rEXP1] = ArrayH::strlen(dest_arrayptr);
38969 }
38970 else ri->d[rEXP1] = output.size();
38971 }
38972 }
38973 1520226 void FFScript::do_varg_max()
38974 {
38975 1520226 int32_t num_args = zs_vargs.size();
38976 1520226 int32_t val = 0;
38977
1/2
✓ Branch 0 taken 1520226 times.
✗ Branch 1 not taken.
1520226 if (num_args > 0)
38978 1520226 val = zs_vargs.at(0);
38979
2/2
✓ Branch 0 taken 1520226 times.
✓ Branch 1 taken 1520226 times.
3040452 for(auto q = 1; q < num_args; ++q)
38980 {
38981 1520226 int32_t tval = zs_vargs.at(q);
38982
2/2
✓ Branch 0 taken 1232999 times.
✓ Branch 1 taken 287227 times.
1520226 if(tval > val) val = tval;
38983 1520226 }
38984 1520226 zs_vargs.clear();
38985 1520226 ri->d[rEXP1] = val;
38986 1520226 }
38987 140579 void FFScript::do_varg_min()
38988 {
38989 140579 int32_t num_args = zs_vargs.size();
38990 140579 int32_t val = 0;
38991
1/2
✓ Branch 0 taken 140579 times.
✗ Branch 1 not taken.
140579 if (num_args > 0)
38992 140579 val = zs_vargs.at(0);
38993
2/2
✓ Branch 0 taken 140579 times.
✓ Branch 1 taken 143253 times.
283832 for(auto q = 1; q < num_args; ++q)
38994 {
38995 143253 int32_t tval = zs_vargs.at(q);
38996
2/2
✓ Branch 0 taken 110082 times.
✓ Branch 1 taken 33171 times.
143253 if(tval < val) val = tval;
38997 143253 }
38998 140579 zs_vargs.clear();
38999 140579 ri->d[rEXP1] = val;
39000 140579 }
39001 5 void FFScript::do_varg_choose()
39002 {
39003 5 int32_t num_args = zs_vargs.size();
39004 5 int32_t val = 0;
39005
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(num_args > 0)
39006 {
39007 5 int32_t choice = zc_rand(num_args-1);
39008 5 val = zs_vargs.at(choice);
39009 5 }
39010 5 zs_vargs.clear();
39011 5 ri->d[rEXP1] = val;
39012 5 }
39013 28 void FFScript::do_varg_makearray(ScriptType type, const uint32_t UID)
39014 {
39015 28 size_t num_args = zs_vargs.size();
39016 //
39017 dword ptrval;
39018
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 28 times.
56 for(ptrval = 1; localRAM[ptrval].Valid(); ptrval++) ;
39019
39020
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
28 if(ptrval >= NUM_ZSCRIPT_ARRAYS)
39021 {
39022 Z_scripterrlog("%d local arrays already in use, no more can be allocated\n", NUM_ZSCRIPT_ARRAYS-1);
39023 ptrval = 0;
39024 }
39025 else
39026 {
39027 28 ZScriptArray &a = localRAM[ptrval]; //marginally faster for large arrays if we use a reference
39028
39029 28 a.Resize(num_args);
39030 28 a.setValid(true);
39031
39032
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 28 times.
68 for(size_t j = 0; j < num_args; ++j)
39033 40 a[j] = zs_vargs[j]; //initialize array
39034
39035 28 arrayOwner[ptrval].clear();
39036 28 arrayOwner[ptrval].reown(type, UID);
39037 }
39038 //
39039 28 zs_vargs.clear();
39040 28 ri->d[rEXP1] = ptrval*10000;
39041 28 }
39042
39043 void FFScript::do_breakpoint()
39044 {
39045 // TODO: implement as `debugger;` statement when VS Code extension exists.
39046 }
39047
39048 void FFScript::do_tracenl()
39049 {
39050 safe_al_trace("\n");
39051
39052 if ( console_enabled )
39053 {
39054 zscript_coloured_console.safeprint((CConsoleLoggerEx::COLOR_WHITE |
39055 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),"\n");
39056 }
39057 }
39058
39059
39060 210808 void FFScript::TraceScriptIDs(bool force_show_context)
39061 {
39062 if(DEVTIMESTAMP)
39063 {
39064 CConsoleLoggerEx console = zscript_coloured_console;
39065 bool cond = console_enabled;
39066
39067 char buf[256] = {0};
39068 //Calculate timestamp
39069 struct tm * tm_struct;
39070 time_t sysRTC;
39071 time (&sysRTC);
39072 tm_struct = localtime (&sysRTC);
39073
39074 sprintf(buf, "[%d:%d:%d] ", tm_struct->tm_hour, tm_struct->tm_min, tm_struct->tm_sec);
39075 //
39076
39077 al_trace("%s", buf);
39078 if ( cond ) {console.safeprint((CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
39079 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),buf); }
39080 }
39081
39082
4/4
✓ Branch 0 taken 165371 times.
✓ Branch 1 taken 45437 times.
✓ Branch 2 taken 40254 times.
✓ Branch 3 taken 5183 times.
210808 bool show_context = force_show_context || (get_qr(qr_TRACESCRIPTIDS) || DEVLOGGING);
39083
2/2
✓ Branch 0 taken 5183 times.
✓ Branch 1 taken 205625 times.
210808 if (show_context)
39084 {
39085 205625 CConsoleLoggerEx console = zscript_coloured_console;
39086 205625 bool cond = console_enabled;
39087 205625 char buf[256] = {0};
39088
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 205619 times.
205625 if(script_funcrun)
39089 {
39090
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 sprintf(buf, "Destructor(%d,%s): ", ri->thiskey, destructstr?destructstr->c_str():"UNKNOWN");
39091 6 }
39092
10/18
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 158730 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 30684 times.
✓ Branch 9 taken 53 times.
✓ Branch 10 taken 10 times.
✓ Branch 11 taken 94 times.
✓ Branch 12 taken 547 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 14528 times.
✓ Branch 17 taken 923 times.
205619 else switch(curScriptType)
39093 {
39094 case ScriptType::Global:
39095 {
39096
2/9
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 14500 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
14528 switch(curScriptNum)
39097 {
39098 case GLOBAL_SCRIPT_INIT:
39099
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 sprintf(buf, "Global Init(%s): ", globalmap[curScriptNum].scriptname.c_str());
39100 28 break;
39101 case GLOBAL_SCRIPT_GAME:
39102
1/2
✓ Branch 0 taken 14500 times.
✗ Branch 1 not taken.
14500 sprintf(buf, "Global Active(%s): ", globalmap[curScriptNum].scriptname.c_str());
39103 14500 break;
39104 case GLOBAL_SCRIPT_END:
39105 sprintf(buf, "Global Exit(%s): ", globalmap[curScriptNum].scriptname.c_str());
39106 break;
39107 case GLOBAL_SCRIPT_ONSAVELOAD:
39108 sprintf(buf, "Global SaveLoad(%s): ", globalmap[curScriptNum].scriptname.c_str());
39109 break;
39110 case GLOBAL_SCRIPT_ONLAUNCH:
39111 sprintf(buf, "Global Launch(%s): ", globalmap[curScriptNum].scriptname.c_str());
39112 break;
39113 case GLOBAL_SCRIPT_ONCONTGAME:
39114 sprintf(buf, "Global ContGame(%s): ", globalmap[curScriptNum].scriptname.c_str());
39115 break;
39116 case GLOBAL_SCRIPT_F6:
39117 sprintf(buf, "Global F6Menu(%s): ", globalmap[curScriptNum].scriptname.c_str());
39118 break;
39119 case GLOBAL_SCRIPT_ONSAVE:
39120 sprintf(buf, "Global Save(%s): ", globalmap[curScriptNum].scriptname.c_str());
39121 break;
39122 }
39123 14528 break;
39124 }
39125
39126 case ScriptType::Hero:
39127 {
39128
1/5
✗ Branch 0 not taken.
✓ Branch 1 taken 923 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
923 switch(curScriptNum)
39129 {
39130 case SCRIPT_HERO_INIT:
39131 sprintf(buf, "Hero Init(%s): ", playermap[curScriptNum-1].scriptname.c_str());
39132 break;
39133 case SCRIPT_HERO_ACTIVE:
39134
1/2
✓ Branch 0 taken 923 times.
✗ Branch 1 not taken.
923 sprintf(buf, "Hero Active(%s): ", playermap[curScriptNum-1].scriptname.c_str());
39135 923 break;
39136 case SCRIPT_HERO_DEATH:
39137 sprintf(buf, "Hero Death(%s): ", playermap[curScriptNum-1].scriptname.c_str());
39138 break;
39139 case SCRIPT_HERO_WIN:
39140 sprintf(buf, "Hero Win(%s): ", playermap[curScriptNum-1].scriptname.c_str());
39141 break;
39142 }
39143 923 break;
39144 }
39145
39146 case ScriptType::Lwpn:
39147
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 sprintf(buf, "LWeapon(%u, %s): ", curScriptNum,lwpnmap[curScriptNum-1].scriptname.c_str());
39148 48 break;
39149
39150 case ScriptType::Ewpn:
39151 sprintf(buf, "EWeapon(%u, %s): ", curScriptNum,ewpnmap[curScriptNum-1].scriptname.c_str());
39152 break;
39153
39154 case ScriptType::NPC:
39155 sprintf(buf, "NPC(%u, %s): ", curScriptNum,npcmap[curScriptNum-1].scriptname.c_str());
39156 break;
39157
39158 case ScriptType::FFC:
39159
1/2
✓ Branch 0 taken 158730 times.
✗ Branch 1 not taken.
158730 sprintf(buf, "FFC(%u, %s): ", curScriptNum,ffcmap[curScriptNum-1].scriptname.c_str());
39160 158730 break;
39161
39162 case ScriptType::Item:
39163 sprintf(buf, "Item(%u, %s): ", curScriptNum,itemmap[curScriptNum-1].scriptname.c_str());
39164 break;
39165
39166 case ScriptType::OnMap:
39167 sprintf(buf, "DMapMap(%u, %s): ", curScriptNum,dmapmap[curScriptNum-1].scriptname.c_str());
39168 break;
39169 case ScriptType::ScriptedActiveSubscreen:
39170 sprintf(buf, "DMapASub(%u, %s): ", curScriptNum,dmapmap[curScriptNum-1].scriptname.c_str());
39171 break;
39172 case ScriptType::ScriptedPassiveSubscreen:
39173
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 sprintf(buf, "DMapPSub(%u, %s): ", curScriptNum,dmapmap[curScriptNum-1].scriptname.c_str());
39174 2 break;
39175 case ScriptType::DMap:
39176
1/2
✓ Branch 0 taken 30684 times.
✗ Branch 1 not taken.
30684 sprintf(buf, "DMap(%u, %s): ", curScriptNum,dmapmap[curScriptNum-1].scriptname.c_str());
39177 30684 break;
39178
39179 case ScriptType::ItemSprite:
39180
1/2
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
53 sprintf(buf, "ItemSprite(%u, %s): ", curScriptNum,itemspritemap[curScriptNum-1].scriptname.c_str());
39181 53 break;
39182
39183 case ScriptType::Screen:
39184
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 sprintf(buf, "Screen(%u, %s): ", curScriptNum,screenmap[curScriptNum-1].scriptname.c_str());
39185 10 break;
39186
39187 case ScriptType::Combo:
39188
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 sprintf(buf, "Combo(%u, %s): ", curScriptNum,comboscriptmap[curScriptNum-1].scriptname.c_str());
39189 94 break;
39190
39191 case ScriptType::Generic:
39192
1/2
✓ Branch 0 taken 547 times.
✗ Branch 1 not taken.
547 sprintf(buf, "Generic(%u, %s): ", curScriptNum,genericmap[curScriptNum-1].scriptname.c_str());
39193 547 break;
39194
39195 case ScriptType::GenericFrozen:
39196 sprintf(buf, "GenericFRZ(%u, %s): ", curScriptNum,genericmap[curScriptNum-1].scriptname.c_str());
39197 break;
39198
39199 case ScriptType::EngineSubscreen:
39200 sprintf(buf, "Subscreen(%u, %s): ", curScriptNum,subscreenmap[curScriptNum-1].scriptname.c_str());
39201 break;
39202 }
39203
39204
1/2
✓ Branch 0 taken 205625 times.
✗ Branch 1 not taken.
205625 al_trace("%s", buf);
39205
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 205625 times.
205625 if ( cond )
39206 console.safeprint((CConsoleLoggerEx::COLOR_GREEN|CConsoleLoggerEx::COLOR_INTENSITY|
39207 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),buf);
39208 205625 }
39209 210808 }
39210
39211 2 void FFScript::do_cleartrace()
39212 {
39213 2 zc_trace_clear();
39214 2 clearConsole();
39215 2 }
39216
39217 3 string inttobase(word base, int32_t x, word mindigits)
39218 {
39219 static const char coeff[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
39220
39221 3 string s2;
39222
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 word digits = zc_max(mindigits - 1, word(floor(log(double(x)) / log(double(base)))));
39223
39224
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 3 times.
14 for(int32_t i = digits; i >= 0; i--)
39225 {
39226
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 s2 += coeff[word(floor(x / pow(double(base), i))) % base];
39227 11 }
39228
39229 3 return s2;
39230
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 }
39231
39232 3 void FFScript::do_tracetobase()
39233 {
39234 3 int32_t x = SH::read_stack(ri->sp + 2) / 10000;
39235 3 uint32_t base = vbound(SH::read_stack(ri->sp + 1) / 10000, 2, 36);
39236
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 uint32_t mindigits = zc_max(1, SH::read_stack(ri->sp) / 10000);
39237
39238
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 string s2 = x < 0 ? "-": "";
39239
39240
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 switch(base)
39241 {
39242 case 8:
39243 s2 += '0';
39244 break;
39245
39246 case 16:
39247 s2 += "0x";
39248 break;
39249 }
39250
39251
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 s2 += inttobase(base, int32_t(fabs(double(x))), mindigits);
39252
39253
2/3
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
3 switch(base)
39254 {
39255 case 8:
39256 case 10:
39257 case 16:
39258 2 break;
39259
39260 case 2:
39261
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 s2 += 'b';
39262 1 break;
39263
39264 default:
39265 std::stringstream ss;
39266 ss << " (Base " << base << ')';
39267 s2 += ss.str();
39268 break;
39269 }
39270
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 TraceScriptIDs();
39271
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 s2 += "\n";
39272
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 al_trace("%s", s2.c_str());
39273
39274
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if ( console_enabled )
39275 {
39276 zscript_coloured_console.safeprint((CConsoleLoggerEx::COLOR_WHITE |
39277 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),s2.c_str());
39278 }
39279 3 }
39280
39281 //SRAM Functions
39282 void FFScript::write_dmaps(PACKFILE *f, int32_t vers_id)
39283 {
39284 word dmap_count=count_dmaps();
39285
39286 dmap_count=zc_min(dmap_count, 512);
39287 dmap_count=zc_min(dmap_count, MAXDMAPS-0);
39288
39289 //finally... section data
39290 if(!p_iputw(dmap_count,f))
39291 {
39292 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",5);
39293 }
39294
39295
39296 for(int32_t i=0; i<dmap_count; i++)
39297 {
39298 if(!p_putc(DMaps[i].map,f))
39299 {
39300 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",6);
39301 }
39302
39303 if(!p_iputw(DMaps[i].level,f))
39304 {
39305 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",7);
39306 }
39307
39308 if(!p_putc(DMaps[i].xoff,f))
39309 {
39310 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",8);
39311 }
39312
39313 if(!p_putc(DMaps[i].compass,f))
39314 {
39315 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",9);
39316 }
39317
39318 if(!p_iputw(DMaps[i].color,f))
39319 {
39320 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",10);
39321 }
39322
39323 if(!p_putc(DMaps[i].midi,f))
39324 {
39325 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",11);
39326 }
39327
39328 if(!p_putc(DMaps[i].cont,f))
39329 {
39330 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",12);
39331 }
39332
39333 if(!p_putc(DMaps[i].type,f))
39334 {
39335 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",13);
39336 }
39337
39338 for(int32_t j=0; j<8; j++)
39339 {
39340 if(!p_putc(DMaps[i].grid[j],f))
39341 {
39342 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",14);
39343 }
39344 }
39345
39346 //16
39347 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name),f))
39348 {
39349 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",15);
39350 }
39351
39352 if(!p_putwstr(DMaps[i].title,f))
39353 {
39354 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",16);
39355 }
39356
39357 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro),f))
39358 {
39359 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",17);
39360 }
39361
39362 if(!p_iputl(DMaps[i].minimap_1_tile,f))
39363 {
39364 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",18);
39365 }
39366
39367 if(!p_putc(DMaps[i].minimap_1_cset,f))
39368 {
39369 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",19);
39370 }
39371
39372 if(!p_iputl(DMaps[i].minimap_2_tile,f))
39373 {
39374 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",20);
39375 }
39376
39377 if(!p_putc(DMaps[i].minimap_2_cset,f))
39378 {
39379 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",21);
39380 }
39381
39382 if(!p_iputl(DMaps[i].largemap_1_tile,f))
39383 {
39384 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",22);
39385 }
39386
39387 if(!p_putc(DMaps[i].largemap_1_cset,f))
39388 {
39389 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",23);
39390 }
39391
39392 if(!p_iputl(DMaps[i].largemap_2_tile,f))
39393 {
39394 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",24);
39395 }
39396
39397 if(!p_putc(DMaps[i].largemap_2_cset,f))
39398 {
39399 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",25);
39400 }
39401
39402 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic),f))
39403 {
39404 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",26);
39405 }
39406
39407 if(!p_putc(DMaps[i].tmusictrack,f))
39408 {
39409 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",25);
39410 }
39411
39412 if(!p_putc(DMaps[i].active_subscreen,f))
39413 {
39414 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",26);
39415 }
39416
39417 if(!p_putc(DMaps[i].passive_subscreen,f))
39418 {
39419 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",27);
39420 }
39421
39422 byte disabled[32];
39423 memset(disabled,0,32);
39424
39425 for(int32_t j=0; j<MAXITEMS; j++)
39426 {
39427 if(DMaps[i].disableditems[j])
39428 {
39429 disabled[j/8] |= (1 << (j%8));
39430 }
39431 }
39432
39433 if(!pfwrite(disabled,32,f))
39434 {
39435 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",28);
39436 }
39437
39438 if(!p_iputl(DMaps[i].flags,f))
39439 {
39440 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",29);
39441 }
39442 if(!p_putc(DMaps[i].sideview,f))
39443 {
39444 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",30);
39445 }
39446 if(!p_iputw(DMaps[i].script,f))
39447 {
39448 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",31);
39449 }
39450 for ( int32_t q = 0; q < 8; q++ )
39451 {
39452 if(!p_iputl(DMaps[i].initD[q],f))
39453 {
39454 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",32);
39455 }
39456
39457 }
39458 for ( int32_t q = 0; q < 8; q++ )
39459 {
39460 for ( int32_t w = 0; w < 65; w++ )
39461 {
39462 if (!p_putc(DMaps[i].initD_label[q][w],f))
39463 {
39464 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",33);
39465 }
39466 }
39467 }
39468 }
39469 }
39470 void FFScript::read_dmaps(PACKFILE *f, int32_t vers_id)
39471 {
39472 word dmap_count=count_dmaps();
39473
39474 dmap_count=zc_min(dmap_count, 512);
39475 dmap_count=zc_min(dmap_count, MAXDMAPS-0);
39476
39477 //finally... section data
39478 if(!p_igetw(&dmap_count,f))
39479 {
39480 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",5);
39481 }
39482
39483
39484 for(int32_t i=0; i<dmap_count; i++)
39485 {
39486 if(!p_getc(&DMaps[i].map,f))
39487 {
39488 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",6);
39489 }
39490
39491 if(!p_igetw(&DMaps[i].level,f))
39492 {
39493 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",7);
39494 }
39495
39496 if(!p_getc(&DMaps[i].xoff,f))
39497 {
39498 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",8);
39499 }
39500
39501 if(!p_getc(&DMaps[i].compass,f))
39502 {
39503 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",9);
39504 }
39505
39506 if(!p_igetw(&DMaps[i].color,f))
39507 {
39508 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",10);
39509 }
39510
39511 if(!p_getc(&DMaps[i].midi,f))
39512 {
39513 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",11);
39514 }
39515
39516 if(!p_getc(&DMaps[i].cont,f))
39517 {
39518 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",12);
39519 }
39520
39521 if(!p_getc(&DMaps[i].type,f))
39522 {
39523 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",13);
39524 }
39525
39526 for(int32_t j=0; j<8; j++)
39527 {
39528 if(!p_getc(&DMaps[i].grid[j],f))
39529 {
39530 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",14);
39531 }
39532 }
39533
39534 //16
39535 if(!pfread((&DMaps[i].name),sizeof(DMaps[0].name),f))
39536 {
39537 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",15);
39538 }
39539
39540 if (!p_getwstr(&DMaps[i].title, f))
39541 {
39542 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",16);
39543 }
39544
39545 if(!pfread((&DMaps[i].intro),sizeof(DMaps[0].intro),f))
39546 {
39547 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",17);
39548 }
39549
39550 if(!p_igetl(&DMaps[i].minimap_1_tile,f))
39551 {
39552 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",18);
39553 }
39554
39555 if(!p_getc(&DMaps[i].minimap_1_cset,f))
39556 {
39557 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",19);
39558 }
39559
39560 if(!p_igetl(&DMaps[i].minimap_2_tile,f))
39561 {
39562 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",20);
39563 }
39564
39565 if(!p_getc(&DMaps[i].minimap_2_cset,f))
39566 {
39567 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",21);
39568 }
39569
39570 if(!p_igetl(&DMaps[i].largemap_1_tile,f))
39571 {
39572 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",22);
39573 }
39574
39575 if(!p_getc(&DMaps[i].largemap_1_cset,f))
39576 {
39577 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",23);
39578 }
39579
39580 if(!p_igetl(&DMaps[i].largemap_2_tile,f))
39581 {
39582 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",24);
39583 }
39584
39585 if(!p_getc(&DMaps[i].largemap_2_cset,f))
39586 {
39587 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",25);
39588 }
39589
39590 if(!pfread((&DMaps[i].tmusic),sizeof(DMaps[0].tmusic),f))
39591 {
39592 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",26);
39593 }
39594
39595 if(!p_getc(&DMaps[i].tmusictrack,f))
39596 {
39597 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",25);
39598 }
39599
39600 if(!p_getc(&DMaps[i].active_subscreen,f))
39601 {
39602 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",26);
39603 }
39604
39605 if(!p_getc(&DMaps[i].passive_subscreen,f))
39606 {
39607 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",27);
39608 }
39609
39610 byte disabled[32];
39611 memset(disabled,0,32);
39612
39613 for(int32_t j=0; j<MAXITEMS; j++)
39614 {
39615 if(&DMaps[i].disableditems[j])
39616 {
39617 disabled[j/8] |= (1 << (j%8));
39618 }
39619 }
39620
39621 if(!pfread(disabled,32,f))
39622 {
39623 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",28);
39624 }
39625
39626 if(!p_igetl(&DMaps[i].flags,f))
39627 {
39628 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",29);
39629 }
39630 if(!p_getc(&DMaps[i].sideview,f))
39631 {
39632 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",30);
39633 }
39634 if(!p_igetw(&DMaps[i].script,f))
39635 {
39636 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",31);
39637 }
39638 for ( int32_t q = 0; q < 8; q++ )
39639 {
39640 if(!p_igetl(&DMaps[i].initD[q],f))
39641 {
39642 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",32);
39643 }
39644
39645 }
39646 for ( int32_t q = 0; q < 8; q++ )
39647 {
39648 for ( int32_t w = 0; w < 65; w++ )
39649 {
39650 if (!p_getc(&DMaps[i].initD_label[q][w],f))
39651 {
39652 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",33);
39653 }
39654 }
39655 }
39656 }
39657 }
39658
39659
39660
39661 void FFScript::read_combos(PACKFILE *f, int32_t version_id)
39662 {
39663
39664 word combos_used = 0;
39665
39666 if(!p_igetw(&combos_used,f))
39667 {
39668 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",5);
39669 }
39670
39671 for(int32_t i=0; i<combos_used; i++)
39672 {
39673 if(!p_igetl(&combobuf[i].tile,f))
39674 {
39675 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",6);
39676 }
39677
39678 if(!p_getc(&combobuf[i].flip,f))
39679 {
39680 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",7);
39681 }
39682
39683 if(!p_getc(&combobuf[i].walk,f))
39684 {
39685 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",8);
39686 }
39687
39688 if(!p_getc(&combobuf[i].type,f))
39689 {
39690 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",9);
39691 }
39692
39693 if(!p_getc(&combobuf[i].csets,f))
39694 {
39695 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",10);
39696 }
39697
39698 if(!p_getc(&combobuf[i].frames,f))
39699 {
39700 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",11);
39701 }
39702
39703 if(!p_getc(&combobuf[i].speed,f))
39704 {
39705 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",12);
39706 }
39707
39708 if(!p_igetw(&combobuf[i].nextcombo,f))
39709 {
39710 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",13);
39711 }
39712
39713 if(!p_getc(&combobuf[i].nextcset,f))
39714 {
39715 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",14);
39716 }
39717
39718 if(!p_getc(&combobuf[i].flag,f))
39719 {
39720 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",15);
39721 }
39722
39723 if(!p_getc(&combobuf[i].skipanim,f))
39724 {
39725 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",16);
39726 }
39727
39728 if(!p_igetw(&combobuf[i].nexttimer,f))
39729 {
39730 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",17);
39731 }
39732
39733 if(!p_getc(&combobuf[i].skipanimy,f))
39734 {
39735 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",18);
39736 }
39737
39738 if(!p_getc(&combobuf[i].animflags,f))
39739 {
39740 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",19);
39741 }
39742
39743 for ( int32_t q = 0; q < NUM_COMBO_ATTRIBUTES; q++ )
39744 {
39745 if(!p_igetl(&combobuf[i].attributes[q],f))
39746 {
39747 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",20);
39748 }
39749 }
39750 if(!p_igetl(&combobuf[i].usrflags,f))
39751 {
39752 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",21);
39753 }
39754 for ( int32_t q = 0; q < 6; q++ )
39755 {
39756 if(!p_igetl(&combobuf[i].triggerflags[q],f))
39757 {
39758 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",22);
39759 }
39760 }
39761
39762 if(!p_igetl(&combobuf[i].triggerlevel,f))
39763 {
39764 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",23);
39765 }
39766 for ( int32_t q = 0; q < 11; q++ )
39767 {
39768 if(!p_getc(&combobuf[i].label[q],f))
39769 {
39770 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",24);
39771 }
39772 }
39773 for ( int32_t q = 0; q < NUM_COMBO_ATTRIBUTES; q++ )
39774 {
39775 if(!p_getc(&combobuf[i].attribytes[q],f))
39776 {
39777 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",25);
39778 }
39779 }
39780 if(!p_igetw(&combobuf[i].script,f))
39781 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",26);
39782 for ( int32_t q = 0; q < 2; q++ )
39783 {
39784 if(!p_igetl(&combobuf[i].initd[q],f))
39785 {
39786 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",27);
39787 }
39788 }
39789 if(!p_igetl(&combobuf[i].o_tile,f))
39790 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",28);
39791 if(!p_getc(&combobuf[i].cur_frame,f))
39792 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",29);
39793 if(!p_getc(&combobuf[i].aclk,f))
39794 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",30);
39795 }
39796
39797 combo_caches::refresh();
39798 }
39799
39800 void FFScript::write_combos(PACKFILE *f, int32_t version_id)
39801 {
39802
39803 word combos_used = 0;
39804
39805 //finally... section data
39806 combos_used=count_combos()-0;
39807 combos_used=zc_min(combos_used, MAXCOMBOS);
39808
39809 if(!p_iputw(combos_used,f))
39810 {
39811 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",5);
39812 }
39813
39814 for(int32_t i=0; i<combos_used; i++)
39815 {
39816 if(!p_iputl(combobuf[i].tile,f))
39817 {
39818 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",6);
39819 }
39820
39821 if(!p_putc(combobuf[i].flip,f))
39822 {
39823 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",7);
39824 }
39825
39826 if(!p_putc(combobuf[i].walk,f))
39827 {
39828 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",8);
39829 }
39830
39831 if(!p_putc(combobuf[i].type,f))
39832 {
39833 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",9);
39834 }
39835
39836 if(!p_putc(combobuf[i].csets,f))
39837 {
39838 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",10);
39839 }
39840
39841 if(!p_putc(combobuf[i].frames,f))
39842 {
39843 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",11);
39844 }
39845
39846 if(!p_putc(combobuf[i].speed,f))
39847 {
39848 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",12);
39849 }
39850
39851 if(!p_iputw(combobuf[i].nextcombo,f))
39852 {
39853 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",13);
39854 }
39855
39856 if(!p_putc(combobuf[i].nextcset,f))
39857 {
39858 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",14);
39859 }
39860
39861 if(!p_putc(combobuf[i].flag,f))
39862 {
39863 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",15);
39864 }
39865
39866 if(!p_putc(combobuf[i].skipanim,f))
39867 {
39868 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",16);
39869 }
39870
39871 if(!p_iputw(combobuf[i].nexttimer,f))
39872 {
39873 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",17);
39874 }
39875
39876 if(!p_putc(combobuf[i].skipanimy,f))
39877 {
39878 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",18);
39879 }
39880
39881 if(!p_putc(combobuf[i].animflags,f))
39882 {
39883 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",19);
39884 }
39885
39886 for ( int32_t q = 0; q < NUM_COMBO_ATTRIBUTES; q++ )
39887 {
39888 if(!p_iputl(combobuf[i].attributes[q],f))
39889 {
39890 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",20);
39891 }
39892 }
39893 if(!p_iputl(combobuf[i].usrflags,f))
39894 {
39895 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",21);
39896 }
39897 for ( int32_t q = 0; q < 6; q++ )
39898 {
39899 if(!p_iputl(combobuf[i].triggerflags[q],f))
39900 {
39901 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",22);
39902 }
39903 }
39904
39905 if(!p_iputl(combobuf[i].triggerlevel,f))
39906 {
39907 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",23);
39908 }
39909 for ( int32_t q = 0; q < 11; q++ )
39910 {
39911 if(!p_putc(combobuf[i].label[q],f))
39912 {
39913 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",24);
39914 }
39915 }
39916 for ( int32_t q = 0; q < NUM_COMBO_ATTRIBUTES; q++ )
39917 {
39918 if(!p_putc(combobuf[i].attribytes[q],f))
39919 {
39920 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",25);
39921 }
39922 }
39923 if(!p_iputw(combobuf[i].script,f))
39924 {
39925 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",26);
39926 }
39927 for ( int32_t q = 0; q < 2; q++ )
39928 {
39929 if(!p_iputl(combobuf[i].initd[q],f))
39930 {
39931 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",27);
39932 }
39933 }
39934 if(!p_iputl(combobuf[i].o_tile,f))
39935 {
39936 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",28);
39937 }
39938 if(!p_putc(combobuf[i].cur_frame,f))
39939 {
39940 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",29);
39941 }
39942 if(!p_putc(combobuf[i].aclk,f))
39943 {
39944 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",30);
39945 }
39946
39947 }
39948 }
39949 void FFScript::read_weaponsprtites(PACKFILE *f, int32_t vers_id)
39950 {
39951 for(int32_t i=0; i<MAXWPNS; i++)
39952 {
39953 word oldtile = 0;
39954 if(!p_igetw(&oldtile,f))
39955 {
39956 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",6);
39957 }
39958
39959 if(!p_getc(&wpnsbuf[i].misc,f))
39960 {
39961 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",7);
39962 }
39963
39964 if(!p_getc(&wpnsbuf[i].csets,f))
39965 {
39966 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",8);
39967 }
39968
39969 if(!p_getc(&wpnsbuf[i].frames,f))
39970 {
39971 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",9);
39972 }
39973
39974 if(!p_getc(&wpnsbuf[i].speed,f))
39975 {
39976 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",10);
39977 }
39978
39979 if(!p_getc(&wpnsbuf[i].type,f))
39980 {
39981 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",11);
39982 }
39983
39984 if(!p_igetw(&wpnsbuf[i].script,f))
39985 {
39986 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",12);
39987 }
39988
39989 if(!p_igetl(&wpnsbuf[i].tile,f))
39990 {
39991 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",12);
39992 }
39993 }
39994 }
39995 void FFScript::write_weaponsprtites(PACKFILE *f, int32_t vers_id)
39996 {
39997 for(int32_t i=0; i<MAXWPNS; i++)
39998 {
39999 if(!p_iputw(wpnsbuf[i].tile,f))
40000 {
40001 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",6);
40002 }
40003
40004 if(!p_putc(wpnsbuf[i].misc,f))
40005 {
40006 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",7);
40007 }
40008
40009 if(!p_putc(wpnsbuf[i].csets,f))
40010 {
40011 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",8);
40012 }
40013
40014 if(!p_putc(wpnsbuf[i].frames,f))
40015 {
40016 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",9);
40017 }
40018
40019 if(!p_putc(wpnsbuf[i].speed,f))
40020 {
40021 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",10);
40022 }
40023
40024 if(!p_putc(wpnsbuf[i].type,f))
40025 {
40026 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",11);
40027 }
40028
40029 if(!p_iputw(wpnsbuf[i].script,f))
40030 {
40031 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",12);
40032 }
40033
40034 if(!p_iputl(wpnsbuf[i].tile,f))
40035 {
40036 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",12);
40037 }
40038 }
40039 }
40040
40041
40042 void FFScript::read_enemies(PACKFILE *f, int32_t vers_id)
40043 {
40044 if ( !f ) return;
40045 for(int32_t i=0; i<MAXGUYS; i++)
40046 {
40047 uint32_t flags1;
40048 uint32_t flags2;
40049 if (!p_igetl(&(flags1), f))
40050 {
40051 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d", 6);
40052 }
40053 if (!p_igetl(&(flags2), f))
40054 {
40055 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d", 7);;
40056 }
40057 guysbuf[i].flags = guy_flags(flags1) | guy_flags(uint64_t(flags2) << 32ULL);
40058
40059 if(!p_igetl(&guysbuf[i].tile,f))
40060 {
40061 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",8);
40062 }
40063
40064 if(!p_getc(&guysbuf[i].width,f))
40065 {
40066 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",9);
40067 }
40068
40069 if(!p_getc(&guysbuf[i].height,f))
40070 {
40071 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",10);
40072 }
40073
40074 if(!p_igetl(&guysbuf[i].s_tile,f))
40075 {
40076 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",11);
40077 }
40078
40079 if(!p_getc(&guysbuf[i].s_width,f))
40080 {
40081 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",12);
40082 }
40083
40084 if(!p_getc(&guysbuf[i].s_height,f))
40085 {
40086 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",13);
40087 }
40088
40089 if(!p_igetl(&guysbuf[i].e_tile,f))
40090 {
40091 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",14);
40092 }
40093
40094 if(!p_getc(&guysbuf[i].e_width,f))
40095 {
40096 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",15);
40097 }
40098
40099 if(!p_getc(&guysbuf[i].e_height,f))
40100 {
40101 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",16);
40102 }
40103
40104 if(!p_igetw(&guysbuf[i].hp,f))
40105 {
40106 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",17);
40107 }
40108
40109 if(!p_igetw(&guysbuf[i].family,f))
40110 {
40111 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",18);
40112 }
40113
40114 if(!p_igetw(&guysbuf[i].cset,f))
40115 {
40116 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",19);
40117 }
40118
40119 if(!p_igetw(&guysbuf[i].anim,f))
40120 {
40121 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",20);
40122 }
40123
40124 if(!p_igetw(&guysbuf[i].e_anim,f))
40125 {
40126 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",21);
40127 }
40128
40129 if(!p_igetw(&guysbuf[i].frate,f))
40130 {
40131 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",22);
40132 }
40133
40134 if(!p_igetw(&guysbuf[i].e_frate,f))
40135 {
40136 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",23);
40137 }
40138
40139 if(!p_igetw(&guysbuf[i].dp,f))
40140 {
40141 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",24);
40142 }
40143
40144 if(!p_igetw(&guysbuf[i].wdp,f))
40145 {
40146 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",25);
40147 }
40148
40149 if(!p_igetw(&guysbuf[i].weapon,f))
40150 {
40151 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",26);
40152 }
40153
40154 if(!p_igetw(&guysbuf[i].rate,f))
40155 {
40156 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",27);
40157 }
40158
40159 if(!p_igetw(&guysbuf[i].hrate,f))
40160 {
40161 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",28);
40162 }
40163
40164 if(!p_igetw(&guysbuf[i].step,f))
40165 {
40166 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",29);
40167 }
40168
40169 if(!p_igetw(&guysbuf[i].homing,f))
40170 {
40171 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",30);
40172 }
40173
40174 if(!p_igetw(&guysbuf[i].grumble,f))
40175 {
40176 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",31);
40177 }
40178
40179 if(!p_igetw(&guysbuf[i].item_set,f))
40180 {
40181 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",32);
40182 }
40183 //misc 1-10
40184 for (int q = 0; q < 10; ++q)
40185 {
40186 if (!p_igetl(&guysbuf[i].attributes[q], f))
40187 {
40188 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d", 33 + q);
40189 }
40190 }
40191
40192 if(!p_igetw(&guysbuf[i].bgsfx,f))
40193 {
40194 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",43);
40195 }
40196
40197 if(!p_igetw(&guysbuf[i].bosspal,f))
40198 {
40199 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",44);
40200 }
40201
40202 if(!p_igetw(&guysbuf[i].extend,f))
40203 {
40204 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",45);
40205 }
40206
40207 for(int32_t j=0; j < edefLAST; j++)
40208 {
40209 if(!p_getc(&guysbuf[i].defense[j],f))
40210 {
40211 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",46);
40212 }
40213 }
40214
40215 if(!p_getc(&guysbuf[i].hitsfx,f))
40216 {
40217 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",47);
40218 }
40219
40220 if(!p_getc(&guysbuf[i].deadsfx,f))
40221 {
40222 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",48);
40223 }
40224 //misc 11-12
40225 for (int q = 0; q < 2; ++q)
40226 {
40227 if (!p_igetl(&guysbuf[i].attributes[10+q], f))
40228 {
40229 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d", 49 + q);
40230 }
40231 }
40232
40233 //New 2.6 defences
40234 for(int32_t j=edefLAST; j < edefLAST255; j++)
40235 {
40236 if(!p_getc(&guysbuf[i].defense[j],f))
40237 {
40238 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",51);
40239 }
40240 }
40241
40242 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
40243 if(!p_igetl(&guysbuf[i].txsz,f))
40244 {
40245 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",52);
40246 }
40247 if(!p_igetl(&guysbuf[i].tysz,f))
40248 {
40249 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",53);
40250 }
40251 if(!p_igetl(&guysbuf[i].hxsz,f))
40252 {
40253 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",54);
40254 }
40255 if(!p_igetl(&guysbuf[i].hysz,f))
40256 {
40257 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",55);
40258 }
40259 if(!p_igetl(&guysbuf[i].hzsz,f))
40260 {
40261 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",56);
40262 }
40263 // These are not fixed types, but ints, so they are safe to use here.
40264 if(!p_igetl(&guysbuf[i].hxofs,f))
40265 {
40266 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",57);
40267 }
40268 if(!p_igetl(&guysbuf[i].hyofs,f))
40269 {
40270 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",58);
40271 }
40272 if(!p_igetl(&guysbuf[i].xofs,f))
40273 {
40274 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",59);
40275 }
40276 if(!p_igetl(&guysbuf[i].yofs,f))
40277 {
40278 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",60);
40279 }
40280 if(!p_igetl(&guysbuf[i].zofs,f))
40281 {
40282 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",61);
40283 }
40284 if(!p_igetl(&guysbuf[i].wpnsprite,f))
40285 {
40286 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",62);
40287 }
40288 if(!p_igetl(&guysbuf[i].SIZEflags,f))
40289 {
40290 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",63);
40291 }
40292 if(!p_igetl(&guysbuf[i].frozentile,f))
40293 {
40294 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",64);
40295 }
40296 if(!p_igetl(&guysbuf[i].frozencset,f))
40297 {
40298 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",65);
40299 }
40300 if(!p_igetl(&guysbuf[i].frozenclock,f))
40301 {
40302 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",66);
40303 }
40304
40305 for ( int32_t q = 0; q < 10; q++ )
40306 {
40307 if(!p_igetw(&guysbuf[i].frozenmisc[q],f))
40308 {
40309 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",67);
40310 }
40311 }
40312 if(!p_igetw(&guysbuf[i].firesfx,f))
40313 {
40314 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",68);
40315 }
40316 //misc 16->32
40317 for (int q = 0; q < 17; ++q)
40318 {
40319 if (!p_igetl(&guysbuf[i].attributes[15 + q], f))
40320 {
40321 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d", 69 + q);
40322 }
40323 }
40324 for ( int32_t q = 0; q < 32; q++ )
40325 {
40326 if(!p_igetl(&guysbuf[i].movement[q],f))
40327 {
40328 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",86);
40329 }
40330 }
40331 for ( int32_t q = 0; q < 32; q++ )
40332 {
40333 if(!p_igetl(&guysbuf[i].new_weapon[q],f))
40334 {
40335 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",87);
40336 }
40337 }
40338 if(!p_igetw(&guysbuf[i].script,f))
40339 {
40340 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",88);
40341 }
40342 for ( int32_t q = 0; q < 8; q++ )
40343 {
40344 if(!p_igetl(&guysbuf[i].initD[q],f))
40345 {
40346 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",89);
40347 }
40348 }
40349 if(!p_igetl(&guysbuf[i].editorflags,f))
40350 {
40351 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",91);
40352 }
40353 //somehow forgot these in the older builds -Z
40354 for (int q = 0; q < 3; ++q)
40355 {
40356 if (!p_igetl(&guysbuf[i].attributes[12 + q], f))
40357 {
40358 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d", 92 + q);
40359 }
40360 }
40361
40362 //Enemy Editor InitD[] labels
40363 for ( int32_t q = 0; q < 8; q++ )
40364 {
40365 for ( int32_t w = 0; w < 65; w++ )
40366 {
40367 if(!p_getc(&guysbuf[i].initD_label[q][w],f))
40368 {
40369 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",95);
40370 }
40371 }
40372 for ( int32_t w = 0; w < 65; w++ )
40373 {
40374 if(!p_getc(&guysbuf[i].weapon_initD_label[q][w],f))
40375 {
40376 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",96);
40377 }
40378 }
40379 }
40380 if(!p_igetw(&guysbuf[i].weaponscript,f))
40381 {
40382 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",97);
40383 }
40384 //eweapon initD
40385 for ( int32_t q = 0; q < 8; q++ )
40386 {
40387 if(!p_igetl(&guysbuf[i].weap_initiald[q],f))
40388 {
40389 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",98);
40390 }
40391 }
40392
40393
40394 }
40395 }
40396
40397 void FFScript::write_enemies(PACKFILE *f, int32_t vers_id)
40398 {
40399 if ( !f ) return;
40400 for(int32_t i=0; i<MAXGUYS; i++)
40401 {
40402 uint32_t flags1 = uint32_t(guysbuf[i].flags);
40403 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
40404 if (!p_iputl(flags1, f))
40405 {
40406 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d", 6);
40407 }
40408 if (!p_iputl(flags2, f))
40409 {
40410 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d", 7);
40411 }
40412
40413 if(!p_iputl(guysbuf[i].tile,f))
40414 {
40415 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",8);
40416 }
40417
40418 if(!p_putc(guysbuf[i].width,f))
40419 {
40420 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",9);
40421 }
40422
40423 if(!p_putc(guysbuf[i].height,f))
40424 {
40425 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",10);
40426 }
40427
40428 if(!p_iputl(guysbuf[i].s_tile,f))
40429 {
40430 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",11);
40431 }
40432
40433 if(!p_putc(guysbuf[i].s_width,f))
40434 {
40435 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",12);
40436 }
40437
40438 if(!p_putc(guysbuf[i].s_height,f))
40439 {
40440 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",13);
40441 }
40442
40443 if(!p_iputl(guysbuf[i].e_tile,f))
40444 {
40445 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",14);
40446 }
40447
40448 if(!p_putc(guysbuf[i].e_width,f))
40449 {
40450 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",15);
40451 }
40452
40453 if(!p_putc(guysbuf[i].e_height,f))
40454 {
40455 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",16);
40456 }
40457
40458 if(!p_iputw(guysbuf[i].hp,f))
40459 {
40460 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",17);
40461 }
40462
40463 if(!p_iputw(guysbuf[i].family,f))
40464 {
40465 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",18);
40466 }
40467
40468 if(!p_iputw(guysbuf[i].cset,f))
40469 {
40470 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",19);
40471 }
40472
40473 if(!p_iputw(guysbuf[i].anim,f))
40474 {
40475 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",20);
40476 }
40477
40478 if(!p_iputw(guysbuf[i].e_anim,f))
40479 {
40480 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",21);
40481 }
40482
40483 if(!p_iputw(guysbuf[i].frate,f))
40484 {
40485 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",22);
40486 }
40487
40488 if(!p_iputw(guysbuf[i].e_frate,f))
40489 {
40490 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",23);
40491 }
40492
40493 if(!p_iputw(guysbuf[i].dp,f))
40494 {
40495 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",24);
40496 }
40497
40498 if(!p_iputw(guysbuf[i].wdp,f))
40499 {
40500 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",25);
40501 }
40502
40503 if(!p_iputw(guysbuf[i].weapon,f))
40504 {
40505 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",26);
40506 }
40507
40508 if(!p_iputw(guysbuf[i].rate,f))
40509 {
40510 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",27);
40511 }
40512
40513 if(!p_iputw(guysbuf[i].hrate,f))
40514 {
40515 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",28);
40516 }
40517
40518 if(!p_iputw(guysbuf[i].step,f))
40519 {
40520 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",29);
40521 }
40522
40523 if(!p_iputw(guysbuf[i].homing,f))
40524 {
40525 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",30);
40526 }
40527
40528 if(!p_iputw(guysbuf[i].grumble,f))
40529 {
40530 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",31);
40531 }
40532
40533 if(!p_iputw(guysbuf[i].item_set,f))
40534 {
40535 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",32);
40536 }
40537
40538 //misc 1-10
40539 for (int q = 0; q < 10; ++q)
40540 {
40541 if (!p_iputl(guysbuf[i].attributes[q], f))
40542 {
40543 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d", 33+q);
40544 }
40545 }
40546
40547 if(!p_iputw(guysbuf[i].bgsfx,f))
40548 {
40549 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",43);
40550 }
40551
40552 if(!p_iputw(guysbuf[i].bosspal,f))
40553 {
40554 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",44);
40555 }
40556
40557 if(!p_iputw(guysbuf[i].extend,f))
40558 {
40559 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",45);
40560 }
40561
40562 for(int32_t j=0; j < edefLAST; j++)
40563 {
40564 if(!p_putc(guysbuf[i].defense[j],f))
40565 {
40566 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",46);
40567 }
40568 }
40569
40570 if(!p_putc(guysbuf[i].hitsfx,f))
40571 {
40572 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",47);
40573 }
40574
40575 if(!p_putc(guysbuf[i].deadsfx,f))
40576 {
40577 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",48);
40578 }
40579
40580 //misc 11-12
40581 for (int q = 0; q < 2; ++q)
40582 {
40583 if (!p_iputl(guysbuf[i].attributes[10+q], f))
40584 {
40585 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d", 49 + q);
40586 }
40587 }
40588
40589 //New 2.6 defences
40590 for(int32_t j=edefLAST; j < edefLAST255; j++)
40591 {
40592 if(!p_putc(guysbuf[i].defense[j],f))
40593 {
40594 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",51);
40595 }
40596 }
40597
40598 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
40599 if(!p_iputl(guysbuf[i].txsz,f))
40600 {
40601 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",52);
40602 }
40603 if(!p_iputl(guysbuf[i].tysz,f))
40604 {
40605 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",53);
40606 }
40607 if(!p_iputl(guysbuf[i].hxsz,f))
40608 {
40609 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",54);
40610 }
40611 if(!p_iputl(guysbuf[i].hysz,f))
40612 {
40613 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",55);
40614 }
40615 if(!p_iputl(guysbuf[i].hzsz,f))
40616 {
40617 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",56);
40618 }
40619 // These are not fixed types, but ints, so they are safe to use here.
40620 if(!p_iputl(guysbuf[i].hxofs,f))
40621 {
40622 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",57);
40623 }
40624 if(!p_iputl(guysbuf[i].hyofs,f))
40625 {
40626 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",58);
40627 }
40628 if(!p_iputl(guysbuf[i].xofs,f))
40629 {
40630 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",59);
40631 }
40632 if(!p_iputl(guysbuf[i].yofs,f))
40633 {
40634 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",60);
40635 }
40636 if(!p_iputl(guysbuf[i].zofs,f))
40637 {
40638 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",61);
40639 }
40640 if(!p_iputl(guysbuf[i].wpnsprite,f))
40641 {
40642 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",62);
40643 }
40644 if(!p_iputl(guysbuf[i].SIZEflags,f))
40645 {
40646 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",63);
40647 }
40648 if(!p_iputl(guysbuf[i].frozentile,f))
40649 {
40650 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",64);
40651 }
40652 if(!p_iputl(guysbuf[i].frozencset,f))
40653 {
40654 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",65);
40655 }
40656 if(!p_iputl(guysbuf[i].frozenclock,f))
40657 {
40658 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",66);
40659 }
40660
40661 for ( int32_t q = 0; q < 10; q++ )
40662 {
40663 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
40664 {
40665 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",67);
40666 }
40667 }
40668
40669 if(!p_iputw(guysbuf[i].firesfx,f))
40670 {
40671 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",68);
40672 }
40673 //misc 16->32
40674 for (int q=0; q < 17; ++q)
40675 {
40676 if (!p_iputl(guysbuf[i].attributes[15 + q], f))
40677 {
40678 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d", 69 + q);
40679 }
40680 }
40681 for ( int32_t q = 0; q < 32; q++ )
40682 {
40683 if(!p_iputl(guysbuf[i].movement[q],f))
40684 {
40685 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",86);
40686 }
40687 }
40688 for ( int32_t q = 0; q < 32; q++ )
40689 {
40690 if(!p_iputl(guysbuf[i].new_weapon[q],f))
40691 {
40692 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",87);
40693 }
40694 }
40695 if(!p_iputw(guysbuf[i].script,f))
40696 {
40697 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",88);
40698 }
40699 for ( int32_t q = 0; q < 8; q++ )
40700 {
40701 if(!p_iputl(guysbuf[i].initD[q],f))
40702 {
40703 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",89);
40704 }
40705 }
40706 if(!p_iputl(guysbuf[i].editorflags,f))
40707 {
40708 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",91);
40709 }
40710 //misc 13-15
40711 for (int q = 0; q < 4; ++q)
40712 {
40713 if (!p_iputl(guysbuf[i].attributes[12 + q], f))
40714 {
40715 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d", 92 + q);
40716 }
40717 }
40718
40719 //Enemy Editor InitD[] labels
40720 for ( int32_t q = 0; q < 8; q++ )
40721 {
40722 for ( int32_t w = 0; w < 65; w++ )
40723 {
40724 if(!p_putc(guysbuf[i].initD_label[q][w],f))
40725 {
40726 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",95);
40727 }
40728 }
40729 for ( int32_t w = 0; w < 65; w++ )
40730 {
40731 if(!p_putc(guysbuf[i].weapon_initD_label[q][w],f))
40732 {
40733 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",96);
40734 }
40735 }
40736 }
40737 if(!p_iputw(guysbuf[i].weaponscript,f))
40738 {
40739 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",97);
40740 }
40741 //eweapon initD
40742 for ( int32_t q = 0; q < 8; q++ )
40743 {
40744 if(!p_iputl(guysbuf[i].weap_initiald[q],f))
40745 {
40746 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",98);
40747 }
40748 }
40749
40750 }
40751 }
40752
40753
40754 void FFScript::write_items(PACKFILE *f, int32_t vers_id)
40755 {
40756 for(int32_t i=0; i<MAXITEMS; i++)
40757 {
40758 if(!p_iputl(itemsbuf[i].tile,f))
40759 {
40760 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",6);
40761 }
40762
40763 if(!p_putc(itemsbuf[i].misc_flags,f))
40764 {
40765 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",7);
40766 }
40767
40768 if(!p_putc(itemsbuf[i].csets,f))
40769 {
40770 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",8);
40771 }
40772
40773 if(!p_putc(itemsbuf[i].frames,f))
40774 {
40775 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",9);
40776 }
40777
40778 if(!p_putc(itemsbuf[i].speed,f))
40779 {
40780 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",10);
40781 }
40782
40783 if(!p_putc(itemsbuf[i].delay,f))
40784 {
40785 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",11);
40786 }
40787
40788 if(!p_iputl(itemsbuf[i].ltm,f))
40789 {
40790 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",12);
40791 }
40792
40793 if(!p_iputl(itemsbuf[i].family,f))
40794 {
40795 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",13);
40796 }
40797
40798 if(!p_putc(itemsbuf[i].fam_type,f))
40799 {
40800 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",14);
40801 }
40802
40803 if(!p_iputl(itemsbuf[i].power,f))
40804 {
40805 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",14);
40806 }
40807
40808 if(!p_iputl(itemsbuf[i].flags,f))
40809 {
40810 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",15);
40811 }
40812
40813 if(!p_iputw(itemsbuf[i].script,f))
40814 {
40815 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",16);
40816 }
40817
40818 if(!p_putc(itemsbuf[i].count,f))
40819 {
40820 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",17);
40821 }
40822
40823 if(!p_iputw(itemsbuf[i].amount,f))
40824 {
40825 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",18);
40826 }
40827
40828 if(!p_iputw(itemsbuf[i].collect_script,f))
40829 {
40830 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",19);
40831 }
40832
40833 if(!p_iputw(itemsbuf[i].setmax,f))
40834 {
40835 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",21);
40836 }
40837
40838 if(!p_iputw(itemsbuf[i].max,f))
40839 {
40840 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",22);
40841 }
40842
40843 if(!p_putc(itemsbuf[i].playsound,f))
40844 {
40845 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",23);
40846 }
40847
40848 for(int32_t j=0; j<8; j++)
40849 {
40850 if(!p_iputl(itemsbuf[i].initiald[j],f))
40851 {
40852 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",24);
40853 }
40854 }
40855
40856 if(!p_putc(itemsbuf[i].wpn,f))
40857 {
40858 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",26);
40859 }
40860
40861 if(!p_putc(itemsbuf[i].wpn2,f))
40862 {
40863 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",27);
40864 }
40865
40866 if(!p_putc(itemsbuf[i].wpn3,f))
40867 {
40868 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",28);
40869 }
40870
40871 if(!p_putc(itemsbuf[i].wpn4,f))
40872 {
40873 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",29);
40874 }
40875
40876 if(!p_putc(itemsbuf[i].wpn5,f))
40877 {
40878 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",30);
40879 }
40880
40881 if(!p_putc(itemsbuf[i].wpn6,f))
40882 {
40883 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",31);
40884 }
40885
40886 if(!p_putc(itemsbuf[i].wpn7,f))
40887 {
40888 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",32);
40889 }
40890
40891 if(!p_putc(itemsbuf[i].wpn8,f))
40892 {
40893 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",33);
40894 }
40895
40896 if(!p_putc(itemsbuf[i].wpn9,f))
40897 {
40898 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",34);
40899 }
40900
40901 if(!p_putc(itemsbuf[i].wpn10,f))
40902 {
40903 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",35);
40904 }
40905
40906 if(!p_putc(itemsbuf[i].pickup_hearts,f))
40907 {
40908 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",36);
40909 }
40910
40911 if(!p_iputl(itemsbuf[i].misc1,f))
40912 {
40913 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",37);
40914 }
40915
40916 if(!p_iputl(itemsbuf[i].misc2,f))
40917 {
40918 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",38);
40919 }
40920
40921 if(!p_putc(itemsbuf[i].cost_amount[0],f))
40922 {
40923 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",39);
40924 }
40925
40926 if(!p_iputl(itemsbuf[i].misc3,f))
40927 {
40928 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",40);
40929 }
40930
40931 if(!p_iputl(itemsbuf[i].misc4,f))
40932 {
40933 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",41);
40934 }
40935
40936 if(!p_iputl(itemsbuf[i].misc5,f))
40937 {
40938 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",42);
40939 }
40940
40941 if(!p_iputl(itemsbuf[i].misc6,f))
40942 {
40943 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",43);
40944 }
40945
40946 if(!p_iputl(itemsbuf[i].misc7,f))
40947 {
40948 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",44);
40949 }
40950
40951 if(!p_iputl(itemsbuf[i].misc8,f))
40952 {
40953 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",45);
40954 }
40955
40956 if(!p_iputl(itemsbuf[i].misc9,f))
40957 {
40958 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",46);
40959 }
40960
40961 if(!p_iputl(itemsbuf[i].misc10,f))
40962 {
40963 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",47);
40964 }
40965
40966 if(!p_putc(itemsbuf[i].usesound,f))
40967 {
40968 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",48);
40969 }
40970
40971 if(!p_putc(itemsbuf[i].usesound2,f))
40972 {
40973 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",48);
40974 }
40975
40976 //New itemdata vars -Z
40977 //! version 27
40978
40979 if(!p_putc(itemsbuf[i].useweapon,f))
40980 {
40981 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",49);
40982 }
40983 if(!p_putc(itemsbuf[i].usedefence,f))
40984 {
40985 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",50);
40986 }
40987 if(!p_iputl(itemsbuf[i].weaprange,f))
40988 {
40989 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",51);
40990 }
40991 if(!p_iputl(itemsbuf[i].weapduration,f))
40992 {
40993 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",52);
40994 }
40995 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
40996 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
40997 {
40998 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",53);
40999 }
41000 }
41001 //version 28
41002 if(!p_iputl(itemsbuf[i].duplicates,f))
41003 {
41004 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",54);
41005 }
41006 for ( int32_t q = 0; q < INITIAL_D; q++ )
41007 {
41008 if(!p_iputl(itemsbuf[i].weap_initiald[q],f))
41009 {
41010 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",55);
41011 }
41012 }
41013
41014 if(!p_putc(itemsbuf[i].drawlayer,f))
41015 {
41016 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",57);
41017 }
41018
41019
41020 if(!p_iputl(itemsbuf[i].hxofs,f))
41021 {
41022 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",58);
41023 }
41024 if(!p_iputl(itemsbuf[i].hyofs,f))
41025 {
41026 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",59);
41027 }
41028 if(!p_iputl(itemsbuf[i].hxsz,f))
41029 {
41030 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",60);
41031 }
41032 if(!p_iputl(itemsbuf[i].hysz,f))
41033 {
41034 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",61);
41035 }
41036 if(!p_iputl(itemsbuf[i].hzsz,f))
41037 {
41038 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",62);
41039 }
41040 if(!p_iputl(itemsbuf[i].xofs,f))
41041 {
41042 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",63);
41043 }
41044 if(!p_iputl(itemsbuf[i].yofs,f))
41045 {
41046 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",64);
41047 }
41048 if(!p_iputl(itemsbuf[i].weap_hxofs,f))
41049 {
41050 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",65);
41051 }
41052 if(!p_iputl(itemsbuf[i].weap_hyofs,f))
41053 {
41054 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",66);
41055 }
41056 if(!p_iputl(itemsbuf[i].weap_hxsz,f))
41057 {
41058 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",67);
41059 }
41060 if(!p_iputl(itemsbuf[i].weap_hysz,f))
41061 {
41062 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",68);
41063 }
41064 if(!p_iputl(itemsbuf[i].weap_hzsz,f))
41065 {
41066 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",69);
41067 }
41068 if(!p_iputl(itemsbuf[i].weap_xofs,f))
41069 {
41070 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",70);
41071 }
41072 if(!p_iputl(itemsbuf[i].weap_yofs,f))
41073 {
41074 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",71);
41075 }
41076 if(!p_iputw(itemsbuf[i].weaponscript,f))
41077 {
41078 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",72);
41079 }
41080 if(!p_iputl(itemsbuf[i].wpnsprite,f))
41081 {
41082 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",73);
41083 }
41084 if(!p_iputl(itemsbuf[i].magiccosttimer[0],f))
41085 {
41086 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",74);
41087 }
41088 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
41089 {
41090 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",75);
41091 }
41092 if(!p_iputl(itemsbuf[i].tilew,f))
41093 {
41094 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",76);
41095 }
41096 if(!p_iputl(itemsbuf[i].tileh,f))
41097 {
41098 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",77);
41099 }
41100 if(!p_iputl(itemsbuf[i].weapoverrideFLAGS,f))
41101 {
41102 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",78);
41103 }
41104 if(!p_iputl(itemsbuf[i].weap_tilew,f))
41105 {
41106 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",79);
41107 }
41108 if(!p_iputl(itemsbuf[i].weap_tileh,f))
41109 {
41110 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",80);
41111 }
41112 if(!p_iputl(itemsbuf[i].pickup,f))
41113 {
41114 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",81);
41115 }
41116 if(!p_iputw(itemsbuf[i].pstring,f))
41117 {
41118 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",82);
41119 }
41120 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
41121 {
41122 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",83);
41123 }
41124
41125 if(!p_putc(itemsbuf[i].cost_counter[0],f))
41126 {
41127 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",84);
41128 }
41129
41130 //InitD[] labels
41131 for ( int32_t q = 0; q < 8; q++ )
41132 {
41133 for ( int32_t w = 0; w < 65; w++ )
41134 {
41135 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
41136 {
41137 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",85);
41138 }
41139 }
41140 for ( int32_t w = 0; w < 65; w++ )
41141 {
41142 if(!p_putc(itemsbuf[i].weapon_initD_label[q][w],f))
41143 {
41144 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",86);
41145 }
41146 }
41147 for ( int32_t w = 0; w < 65; w++ )
41148 {
41149 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
41150 {
41151 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",87);
41152 }
41153 }
41154 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
41155 {
41156 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",88);
41157 }
41158 }
41159
41160 if(!p_iputw(itemsbuf[i].sprite_script,f))
41161 {
41162 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",90);
41163 }
41164
41165
41166 }
41167 }
41168
41169 void FFScript::read_items(PACKFILE *f, int32_t vers_id)
41170 {
41171 for(int32_t i=0; i<MAXITEMS; i++)
41172 {
41173 if(!p_igetl(&itemsbuf[i].tile,f))
41174 {
41175 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",6);
41176 }
41177
41178 if(!p_getc(&itemsbuf[i].misc_flags,f))
41179 {
41180 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",7);
41181 }
41182
41183 if(!p_getc(&itemsbuf[i].csets,f))
41184 {
41185 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",8);
41186 }
41187
41188 if(!p_getc(&itemsbuf[i].frames,f))
41189 {
41190 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",9);
41191 }
41192
41193 if(!p_getc(&itemsbuf[i].speed,f))
41194 {
41195 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",10);
41196 }
41197
41198 if(!p_getc(&itemsbuf[i].delay,f))
41199 {
41200 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",11);
41201 }
41202
41203 if(!p_igetl(&itemsbuf[i].ltm,f))
41204 {
41205 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",12);
41206 }
41207
41208 if(!p_igetl(&itemsbuf[i].family,f))
41209 {
41210 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",13);
41211 }
41212
41213 if(!p_getc(&itemsbuf[i].fam_type,f))
41214 {
41215 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",14);
41216 }
41217
41218 if(!p_igetl(&itemsbuf[i].power,f))
41219 {
41220 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",14);
41221 }
41222
41223 if(!p_igetl(&itemsbuf[i].flags,f))
41224 {
41225 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",15);
41226 }
41227
41228 if(!p_igetw(&itemsbuf[i].script,f))
41229 {
41230 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",16);
41231 }
41232
41233 if(!p_getc(&itemsbuf[i].count,f))
41234 {
41235 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",17);
41236 }
41237
41238 if(!p_igetw(&itemsbuf[i].amount,f))
41239 {
41240 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",18);
41241 }
41242
41243 if(!p_igetw(&itemsbuf[i].collect_script,f))
41244 {
41245 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",19);
41246 }
41247
41248 if(!p_igetw(&itemsbuf[i].setmax,f))
41249 {
41250 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",21);
41251 }
41252
41253 if(!p_igetw(&itemsbuf[i].max,f))
41254 {
41255 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",22);
41256 }
41257
41258 if(!p_getc(&itemsbuf[i].playsound,f))
41259 {
41260 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",23);
41261 }
41262
41263 for(int32_t j=0; j<8; j++)
41264 {
41265 if(!p_igetl(&itemsbuf[i].initiald[j],f))
41266 {
41267 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",24);
41268 }
41269 }
41270
41271 if(!p_getc(&itemsbuf[i].wpn,f))
41272 {
41273 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",26);
41274 }
41275
41276 if(!p_getc(&itemsbuf[i].wpn2,f))
41277 {
41278 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",27);
41279 }
41280
41281 if(!p_getc(&itemsbuf[i].wpn3,f))
41282 {
41283 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",28);
41284 }
41285
41286 if(!p_getc(&itemsbuf[i].wpn4,f))
41287 {
41288 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",29);
41289 }
41290
41291 if(!p_getc(&itemsbuf[i].wpn5,f))
41292 {
41293 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",30);
41294 }
41295
41296 if(!p_getc(&itemsbuf[i].wpn6,f))
41297 {
41298 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",31);
41299 }
41300
41301 if(!p_getc(&itemsbuf[i].wpn7,f))
41302 {
41303 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",32);
41304 }
41305
41306 if(!p_getc(&itemsbuf[i].wpn8,f))
41307 {
41308 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",33);
41309 }
41310
41311 if(!p_getc(&itemsbuf[i].wpn9,f))
41312 {
41313 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",34);
41314 }
41315
41316 if(!p_getc(&itemsbuf[i].wpn10,f))
41317 {
41318 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",35);
41319 }
41320
41321 if(!p_getc(&itemsbuf[i].pickup_hearts,f))
41322 {
41323 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",36);
41324 }
41325
41326 if(!p_igetl(&itemsbuf[i].misc1,f))
41327 {
41328 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",37);
41329 }
41330
41331 if(!p_igetl(&itemsbuf[i].misc2,f))
41332 {
41333 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",38);
41334 }
41335
41336 if(!p_getc(&itemsbuf[i].cost_amount[0],f))
41337 {
41338 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",39);
41339 }
41340
41341 if(!p_igetl(&itemsbuf[i].misc3,f))
41342 {
41343 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",40);
41344 }
41345
41346 if(!p_igetl(&itemsbuf[i].misc4,f))
41347 {
41348 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",41);
41349 }
41350
41351 if(!p_igetl(&itemsbuf[i].misc5,f))
41352 {
41353 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",42);
41354 }
41355
41356 if(!p_igetl(&itemsbuf[i].misc6,f))
41357 {
41358 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",43);
41359 }
41360
41361 if(!p_igetl(&itemsbuf[i].misc7,f))
41362 {
41363 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",44);
41364 }
41365
41366 if(!p_igetl(&itemsbuf[i].misc8,f))
41367 {
41368 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",45);
41369 }
41370
41371 if(!p_igetl(&itemsbuf[i].misc9,f))
41372 {
41373 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",46);
41374 }
41375
41376 if(!p_igetl(&itemsbuf[i].misc10,f))
41377 {
41378 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",47);
41379 }
41380
41381 if(!p_getc(&itemsbuf[i].usesound,f))
41382 {
41383 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",48);
41384 }
41385
41386 if(!p_getc(&itemsbuf[i].usesound2,f))
41387 {
41388 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",48);
41389 }
41390
41391 //New itemdata vars -Z
41392 //! version 27
41393
41394 if(!p_getc(&itemsbuf[i].useweapon,f))
41395 {
41396 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",49);
41397 }
41398 if(!p_getc(&itemsbuf[i].usedefence,f))
41399 {
41400 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",50);
41401 }
41402 if(!p_igetl(&itemsbuf[i].weaprange,f))
41403 {
41404 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",51);
41405 }
41406 if(!p_igetl(&itemsbuf[i].weapduration,f))
41407 {
41408 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",52);
41409 }
41410 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
41411 if(!p_igetl(&itemsbuf[i].weap_pattern[q],f))
41412 {
41413 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",53);
41414 }
41415 }
41416 //version 28
41417 if(!p_igetl(&itemsbuf[i].duplicates,f))
41418 {
41419 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",54);
41420 }
41421 for ( int32_t q = 0; q < INITIAL_D; q++ )
41422 {
41423 if(!p_igetl(&itemsbuf[i].weap_initiald[q],f))
41424 {
41425 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",55);
41426 }
41427 }
41428
41429 if(!p_getc(&itemsbuf[i].drawlayer,f))
41430 {
41431 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",57);
41432 }
41433
41434
41435 if(!p_igetl(&itemsbuf[i].hxofs,f))
41436 {
41437 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",58);
41438 }
41439 if(!p_igetl(&itemsbuf[i].hyofs,f))
41440 {
41441 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",59);
41442 }
41443 if(!p_igetl(&itemsbuf[i].hxsz,f))
41444 {
41445 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",60);
41446 }
41447 if(!p_igetl(&itemsbuf[i].hysz,f))
41448 {
41449 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",61);
41450 }
41451 if(!p_igetl(&itemsbuf[i].hzsz,f))
41452 {
41453 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",62);
41454 }
41455 if(!p_igetl(&itemsbuf[i].xofs,f))
41456 {
41457 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",63);
41458 }
41459 if(!p_igetl(&itemsbuf[i].yofs,f))
41460 {
41461 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",64);
41462 }
41463 if(!p_igetl(&itemsbuf[i].weap_hxofs,f))
41464 {
41465 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",65);
41466 }
41467 if(!p_igetl(&itemsbuf[i].weap_hyofs,f))
41468 {
41469 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",66);
41470 }
41471 if(!p_igetl(&itemsbuf[i].weap_hxsz,f))
41472 {
41473 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",67);
41474 }
41475 if(!p_igetl(&itemsbuf[i].weap_hysz,f))
41476 {
41477 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",68);
41478 }
41479 if(!p_igetl(&itemsbuf[i].weap_hzsz,f))
41480 {
41481 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",69);
41482 }
41483 if(!p_igetl(&itemsbuf[i].weap_xofs,f))
41484 {
41485 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",70);
41486 }
41487 if(!p_igetl(&itemsbuf[i].weap_yofs,f))
41488 {
41489 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",71);
41490 }
41491 if(!p_igetw(&itemsbuf[i].weaponscript,f))
41492 {
41493 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",72);
41494 }
41495 if(!p_igetl(&itemsbuf[i].wpnsprite,f))
41496 {
41497 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",73);
41498 }
41499 if(!p_igetl(&itemsbuf[i].magiccosttimer[0],f))
41500 {
41501 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",74);
41502 }
41503 if(!p_igetl(&itemsbuf[i].overrideFLAGS,f))
41504 {
41505 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",75);
41506 }
41507 if(!p_igetl(&itemsbuf[i].tilew,f))
41508 {
41509 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",76);
41510 }
41511 if(!p_igetl(&itemsbuf[i].tileh,f))
41512 {
41513 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",77);
41514 }
41515 if(!p_igetl(&itemsbuf[i].weapoverrideFLAGS,f))
41516 {
41517 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",78);
41518 }
41519 if(!p_igetl(&itemsbuf[i].weap_tilew,f))
41520 {
41521 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",79);
41522 }
41523 if(!p_igetl(&itemsbuf[i].weap_tileh,f))
41524 {
41525 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",80);
41526 }
41527 if(!p_igetl(&itemsbuf[i].pickup,f))
41528 {
41529 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",81);
41530 }
41531 if(!p_igetw(&itemsbuf[i].pstring,f))
41532 {
41533 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",82);
41534 }
41535 if(!p_igetw(&itemsbuf[i].pickup_string_flags,f))
41536 {
41537 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",83);
41538 }
41539
41540 if(!p_getc(&itemsbuf[i].cost_counter[0],f))
41541 {
41542 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",84);
41543 }
41544
41545 //InitD[] labels
41546 for ( int32_t q = 0; q < 8; q++ )
41547 {
41548 for ( int32_t w = 0; w < 65; w++ )
41549 {
41550 if(!p_getc(&itemsbuf[i].initD_label[q][w],f))
41551 {
41552 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",85);
41553 }
41554 }
41555 for ( int32_t w = 0; w < 65; w++ )
41556 {
41557 if(!p_getc(&itemsbuf[i].weapon_initD_label[q][w],f))
41558 {
41559 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",86);
41560 }
41561 }
41562 for ( int32_t w = 0; w < 65; w++ )
41563 {
41564 if(!p_getc(&itemsbuf[i].sprite_initD_label[q][w],f))
41565 {
41566 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",87);
41567 }
41568 }
41569 if(!p_igetl(&itemsbuf[i].sprite_initiald[q],f))
41570 {
41571 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",88);
41572 }
41573 }
41574
41575 if(!p_igetw(&itemsbuf[i].sprite_script,f))
41576 {
41577 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",90);
41578 }
41579
41580
41581 }
41582 }
41583
41584 void FFScript::write_mapscreens(PACKFILE *f,int32_t vers_id)
41585 {
41586
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 310 times.
310 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
41587 {
41588
2/2
✓ Branch 0 taken 42160 times.
✓ Branch 1 taken 310 times.
42470 for(int32_t j=0; j<MAPSCRS; j++)
41589 {
41590 42160 mapscr *m = &TheMaps[i*MAPSCRS+j];
41591
41592
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->valid,f))
41593 {
41594 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41595 }
41596
41597
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->guy,f))
41598 {
41599 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41600 }
41601
41602 {
41603
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_iputw(m->str,f))
41604 {
41605 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41606 }
41607 }
41608
41609
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->room,f))
41610 {
41611 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41612 }
41613
41614
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->item,f))
41615 {
41616 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41617 }
41618
41619
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->hasitem, f))
41620 {
41621 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41622 }
41623
41624
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
41625 {
41626
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168640 times.
168640 if(!p_putc(m->tilewarptype[k],f))
41627 {
41628 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41629 }
41630 168640 }
41631
41632
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_iputw(m->door_combo_set,f))
41633 {
41634 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41635 }
41636
41637
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
41638 {
41639
1/2
✓ Branch 0 taken 168640 times.
✗ Branch 1 not taken.
168640 if(!p_putc(m->warpreturnx[k],f))
41640 {
41641 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41642 }
41643 168640 }
41644
41645
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
41646 {
41647
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168640 times.
168640 if(!p_putc(m->warpreturny[k],f))
41648 {
41649 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41650 }
41651 168640 }
41652
41653
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_iputw(m->warpreturnc,f))
41654 {
41655 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41656 }
41657
41658
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->stairx,f))
41659 {
41660 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41661 }
41662
41663
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->stairy,f))
41664 {
41665 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41666 }
41667
41668
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->itemx,f))
41669 {
41670 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41671 }
41672
41673
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->itemy,f))
41674 {
41675 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41676 }
41677
41678
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_iputw(m->color,f))
41679 {
41680 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41681 }
41682
41683
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->flags11,f))
41684 {
41685 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41686 }
41687
41688
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
41689 {
41690
1/2
✓ Branch 0 taken 168640 times.
✗ Branch 1 not taken.
168640 if(!p_putc(m->door[k],f))
41691 {
41692 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41693 }
41694 168640 }
41695
41696
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
41697 {
41698
1/2
✓ Branch 0 taken 168640 times.
✗ Branch 1 not taken.
168640 if(!p_iputw(m->tilewarpdmap[k],f))
41699 {
41700 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41701 }
41702 168640 }
41703
41704
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
41705 {
41706
1/2
✓ Branch 0 taken 168640 times.
✗ Branch 1 not taken.
168640 if(!p_putc(m->tilewarpscr[k],f))
41707 {
41708 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41709 }
41710 168640 }
41711
41712
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->tilewarpoverlayflags,f))
41713 {
41714 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41715 }
41716
41717
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->exitdir,f))
41718 {
41719 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41720 }
41721
41722
2/2
✓ Branch 0 taken 421600 times.
✓ Branch 1 taken 42160 times.
463760 for(int32_t k=0; k<10; k++)
41723 {
41724 {
41725
1/2
✓ Branch 0 taken 421600 times.
✗ Branch 1 not taken.
421600 if(!p_iputw(m->enemy[k],f))
41726 {
41727 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41728 }
41729 }
41730 421600 }
41731
41732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->pattern,f))
41733 {
41734 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41735 }
41736
41737
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
41738 {
41739
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168640 times.
168640 if(!p_putc(m->sidewarptype[k],f))
41740 {
41741 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41742 }
41743 168640 }
41744
41745
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->sidewarpoverlayflags,f))
41746 {
41747 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41748 }
41749
41750
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->warparrivalx,f))
41751 {
41752 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41753 }
41754
41755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->warparrivaly,f))
41756 {
41757 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41758 }
41759
41760
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
41761 {
41762
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168640 times.
168640 if(!p_putc(m->path[k],f))
41763 {
41764 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41765 }
41766 168640 }
41767
41768
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
41769 {
41770
1/2
✓ Branch 0 taken 168640 times.
✗ Branch 1 not taken.
168640 if(!p_putc(m->sidewarpscr[k],f))
41771 {
41772 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41773 }
41774 168640 }
41775
41776
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
41777 {
41778
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168640 times.
168640 if(!p_iputw(m->sidewarpdmap[k],f))
41779 {
41780 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41781 }
41782 168640 }
41783
41784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->sidewarpindex,f))
41785 {
41786 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41787 }
41788
41789
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_iputw(m->undercombo,f))
41790 {
41791 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41792 }
41793
41794
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->undercset,f))
41795 {
41796 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41797 }
41798
41799
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_iputw(m->catchall,f))
41800 {
41801 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41802 }
41803
41804
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->flags,f))
41805 {
41806 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41807 }
41808
41809
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->flags2,f))
41810 {
41811 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41812 }
41813
41814
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->flags3,f))
41815 {
41816 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41817 }
41818
41819
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->flags4,f))
41820 {
41821 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41822 }
41823
41824
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->flags5,f))
41825 {
41826 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41827 }
41828
41829
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_iputw(m->noreset,f))
41830 {
41831 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41832 }
41833
41834
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_iputw(m->nocarry,f))
41835 {
41836 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41837 }
41838
41839
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->flags6,f))
41840 {
41841 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41842 }
41843
41844
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->flags7,f))
41845 {
41846 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41847 }
41848
41849
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->flags8,f))
41850 {
41851 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41852 }
41853
41854
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->flags9,f))
41855 {
41856 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41857 }
41858
41859
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->flags10,f))
41860 {
41861 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41862 }
41863
41864
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->csensitive,f))
41865 {
41866 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41867 }
41868
41869
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->oceansfx,f))
41870 {
41871 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41872 }
41873
41874
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->bosssfx,f))
41875 {
41876 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41877 }
41878
41879
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->secretsfx,f))
41880 {
41881 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41882 }
41883
41884
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->holdupsfx,f))
41885 {
41886 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41887 }
41888
41889
2/2
✓ Branch 0 taken 252960 times.
✓ Branch 1 taken 42160 times.
295120 for(int32_t k=0; k<6; k++)
41890 {
41891
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252960 times.
252960 if(!p_putc(m->layermap[k],f))
41892 {
41893 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41894 }
41895 252960 }
41896
41897
2/2
✓ Branch 0 taken 252960 times.
✓ Branch 1 taken 42160 times.
295120 for(int32_t k=0; k<6; k++)
41898 {
41899
1/2
✓ Branch 0 taken 252960 times.
✗ Branch 1 not taken.
252960 if(!p_putc(m->layerscreen[k],f))
41900 {
41901 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41902 }
41903 252960 }
41904
41905
2/2
✓ Branch 0 taken 252960 times.
✓ Branch 1 taken 42160 times.
295120 for(int32_t k=0; k<6; k++)
41906 {
41907
1/2
✓ Branch 0 taken 252960 times.
✗ Branch 1 not taken.
252960 if(!p_putc(m->layeropacity[k],f))
41908 {
41909 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41910 }
41911 252960 }
41912
41913
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_iputw(m->timedwarptics,f))
41914 {
41915 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41916 }
41917
41918
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->nextmap,f))
41919 {
41920 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41921 }
41922
41923
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->nextscr,f))
41924 {
41925 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41926 }
41927
41928
2/2
✓ Branch 0 taken 5396480 times.
✓ Branch 1 taken 42160 times.
5438640 for(int32_t k=0; k<128; k++)
41929 {
41930
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5396480 times.
5396480 if(!p_iputw(m->secretcombo[k],f))
41931 {
41932 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41933 }
41934 5396480 }
41935
41936
2/2
✓ Branch 0 taken 5396480 times.
✓ Branch 1 taken 42160 times.
5438640 for(int32_t k=0; k<128; k++)
41937 {
41938
1/2
✓ Branch 0 taken 5396480 times.
✗ Branch 1 not taken.
5396480 if(!p_putc(m->secretcset[k],f))
41939 {
41940 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41941 }
41942 5396480 }
41943
41944
2/2
✓ Branch 0 taken 5396480 times.
✓ Branch 1 taken 42160 times.
5438640 for(int32_t k=0; k<128; k++)
41945 {
41946
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5396480 times.
5396480 if(!p_putc(m->secretflag[k],f))
41947 {
41948 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41949 }
41950 5396480 }
41951
41952
2/2
✓ Branch 0 taken 7420160 times.
✓ Branch 1 taken 42160 times.
7462320 for(int32_t k=0; k<176; k++)
41953 {
41954 try
41955 {
41956
2/4
✓ Branch 0 taken 7420160 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7420160 times.
7420160 if(!p_iputw(m->data[k],f))
41957 {
41958 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41959 }
41960
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
7420160 }
41961 catch(std::out_of_range& )
41962 {
41963 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41964 }
41965 7420160 }
41966
41967
2/2
✓ Branch 0 taken 7420160 times.
✓ Branch 1 taken 42160 times.
7462320 for(int32_t k=0; k<176; k++)
41968 {
41969 try
41970 {
41971
2/4
✓ Branch 0 taken 7420160 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7420160 times.
7420160 if(!p_putc(m->sflag[k], f))
41972 {
41973 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41974 }
41975
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
7420160 }
41976 catch(std::out_of_range& )
41977 {
41978 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41979 }
41980 7420160 }
41981
41982
2/2
✓ Branch 0 taken 7420160 times.
✓ Branch 1 taken 42160 times.
7462320 for(int32_t k=0; k<176; k++)
41983 {
41984 try
41985 {
41986
2/4
✓ Branch 0 taken 7420160 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7420160 times.
7420160 if(!p_putc(m->cset[k],f))
41987 {
41988 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41989 }
41990
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
7420160 }
41991 catch(std::out_of_range& )
41992 {
41993 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
41994 }
41995 7420160 }
41996
41997
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_iputw(m->screen_midi,f))
41998 {
41999 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42000 }
42001
42002
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->lens_layer,f))
42003 {
42004 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42005 }
42006
42007 42160 m->ensureFFC(32);
42008
2/2
✓ Branch 0 taken 1349120 times.
✓ Branch 1 taken 42160 times.
1391280 for(int32_t k=0; k<32; k++)
42009 {
42010 1349120 ffcdata& ffc = m->ffcs[k];
42011
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputw(ffc.data,f))
42012 {
42013 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42014 }
42015
42016
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_putc(ffc.cset,f))
42017 {
42018 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42019 }
42020
42021
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputw(ffc.delay,f))
42022 {
42023 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42024 }
42025
42026
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputzf(ffc.x,f))
42027 {
42028 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42029 }
42030
42031
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputzf(ffc.y,f))
42032 {
42033 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42034 }
42035
42036
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputzf(ffc.vx,f))
42037 {
42038 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42039 }
42040
42041
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputzf(ffc.vy,f))
42042 {
42043 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42044 }
42045
42046
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputzf(ffc.ax,f))
42047 {
42048 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42049 }
42050
42051
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputzf(ffc.ay,f))
42052 {
42053 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42054 }
42055
42056
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_putc(ffc.link,f))
42057 {
42058 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42059 }
42060
42061
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputl(ffc.hit_width,f))
42062 {
42063 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42064 }
42065
42066
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputl(ffc.hit_height,f))
42067 {
42068 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42069 }
42070
42071
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_putc(ffc.txsz,f))
42072 {
42073 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42074 }
42075
42076
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_putc(ffc.tysz,f))
42077 {
42078 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42079 }
42080
42081
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputl(ffc.flags,f))
42082 {
42083 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42084 }
42085
42086
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputw(ffc.script,f))
42087 {
42088 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42089 }
42090
42091
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputl(ffc.initd[0],f))
42092 {
42093 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42094 }
42095
42096
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputl(ffc.initd[1],f))
42097 {
42098 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42099 }
42100
42101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputl(ffc.initd[2],f))
42102 {
42103 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42104 }
42105
42106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputl(ffc.initd[3],f))
42107 {
42108 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42109 }
42110
42111
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputl(ffc.initd[4],f))
42112 {
42113 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42114 }
42115
42116
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputl(ffc.initd[5],f))
42117 {
42118 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42119 }
42120
42121
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputl(ffc.initd[6],f))
42122 {
42123 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42124 }
42125
42126
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputl(ffc.initd[7],f))
42127 {
42128 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42129 }
42130
42131 1349120 }
42132
42133
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_iputw(m->script,f))
42134 {
42135 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42136 }
42137
2/2
✓ Branch 0 taken 337280 times.
✓ Branch 1 taken 42160 times.
379440 for ( int32_t q = 0; q < 8; q++ )
42138 {
42139
1/2
✓ Branch 0 taken 337280 times.
✗ Branch 1 not taken.
337280 if(!p_iputl(m->screeninitd[q],f))
42140 {
42141 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42142 }
42143
42144 337280 }
42145
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->preloadscript,f))
42146 {
42147 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42148 }
42149
42150
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->hidelayers,f))
42151 {
42152 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42153 }
42154
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->hidescriptlayers,f))
42155 {
42156 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
42157 }
42158
42159
42160 42160 } //end mapscr for loop
42161 310 }
42162 }
42163 void FFScript::read_mapscreens(PACKFILE *f,int32_t vers_id)
42164 {
42165 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
42166 {
42167 for(int32_t j=0; j<MAPSCRS; j++)
42168 {
42169 mapscr *m = &TheMaps[i*MAPSCRS+j];
42170
42171 if(!p_getc(&(m->valid),f))
42172 {
42173 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42174 }
42175
42176 if(!p_getc(&(m->guy),f))
42177 {
42178 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42179 }
42180
42181 {
42182 if(!p_igetw(&(m->str),f))
42183 {
42184 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42185 }
42186 }
42187
42188 if(!p_getc(&(m->room),f))
42189 {
42190 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42191 }
42192
42193 if(!p_getc(&(m->item),f))
42194 {
42195 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42196 }
42197
42198 if(!p_getc(&(m->hasitem), f))
42199 {
42200 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42201 }
42202
42203 for(int32_t k=0; k<4; k++)
42204 {
42205 if(!p_getc(&(m->tilewarptype[k]),f))
42206 {
42207 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42208 }
42209 }
42210
42211 if(!p_igetw(&(m->door_combo_set),f))
42212 {
42213 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42214 }
42215
42216 for(int32_t k=0; k<4; k++)
42217 {
42218 if(!p_getc(&(m->warpreturnx[k]),f))
42219 {
42220 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42221 }
42222 }
42223
42224 for(int32_t k=0; k<4; k++)
42225 {
42226 if(!p_getc(&(m->warpreturny[k]),f))
42227 {
42228 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42229 }
42230 }
42231
42232 if(!p_igetw(&(m->warpreturnc),f))
42233 {
42234 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42235 }
42236
42237 if(!p_getc(&(m->stairx),f))
42238 {
42239 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42240 }
42241
42242 if(!p_getc(&(m->stairy),f))
42243 {
42244 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42245 }
42246
42247 if(!p_getc(&(m->itemx),f))
42248 {
42249 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42250 }
42251
42252 if(!p_getc(&(m->itemy),f))
42253 {
42254 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42255 }
42256
42257 if(!p_igetw(&(m->color),f))
42258 {
42259 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42260 }
42261
42262 if(!p_getc(&(m->flags11),f))
42263 {
42264 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42265 }
42266
42267 for(int32_t k=0; k<4; k++)
42268 {
42269 if(!p_getc(&(m->door[k]),f))
42270 {
42271 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42272 }
42273 }
42274
42275 for(int32_t k=0; k<4; k++)
42276 {
42277 if(!p_igetw(&(m->tilewarpdmap[k]),f))
42278 {
42279 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42280 }
42281 }
42282
42283 for(int32_t k=0; k<4; k++)
42284 {
42285 if(!p_getc(&(m->tilewarpscr[k]),f))
42286 {
42287 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42288 }
42289 }
42290
42291 if(!p_getc(&(m->tilewarpoverlayflags),f))
42292 {
42293 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42294 }
42295
42296 if(!p_getc(&(m->exitdir),f))
42297 {
42298 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42299 }
42300
42301 for(int32_t k=0; k<10; k++)
42302 {
42303 {
42304 if(!p_igetw(&(m->enemy[k]),f))
42305 {
42306 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42307 }
42308 }
42309 }
42310
42311 if(!p_getc(&(m->pattern),f))
42312 {
42313 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42314 }
42315
42316 for(int32_t k=0; k<4; k++)
42317 {
42318 if(!p_getc(&(m->sidewarptype[k]),f))
42319 {
42320 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42321 }
42322 }
42323
42324 if(!p_getc(&(m->sidewarpoverlayflags),f))
42325 {
42326 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42327 }
42328
42329 if(!p_getc(&(m->warparrivalx),f))
42330 {
42331 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42332 }
42333
42334 if(!p_getc(&(m->warparrivaly),f))
42335 {
42336 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42337 }
42338
42339 for(int32_t k=0; k<4; k++)
42340 {
42341 if(!p_getc(&(m->path[k]),f))
42342 {
42343 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42344 }
42345 }
42346
42347 for(int32_t k=0; k<4; k++)
42348 {
42349 if(!p_getc(&(m->sidewarpscr[k]),f))
42350 {
42351 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42352 }
42353 }
42354
42355 for(int32_t k=0; k<4; k++)
42356 {
42357 if(!p_igetw(&(m->sidewarpdmap[k]),f))
42358 {
42359 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42360 }
42361 }
42362
42363 if(!p_getc(&(m->sidewarpindex),f))
42364 {
42365 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42366 }
42367
42368 if(!p_igetw(&(m->undercombo),f))
42369 {
42370 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42371 }
42372
42373 if(!p_getc(&(m->undercset),f))
42374 {
42375 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42376 }
42377
42378 if(!p_igetw(&(m->catchall),f))
42379 {
42380 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42381 }
42382
42383 if(!p_getc(&(m->flags),f))
42384 {
42385 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42386 }
42387
42388 if(!p_getc(&(m->flags2),f))
42389 {
42390 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42391 }
42392
42393 if(!p_getc(&(m->flags3),f))
42394 {
42395 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42396 }
42397
42398 if(!p_getc(&(m->flags4),f))
42399 {
42400 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42401 }
42402
42403 if(!p_getc(&(m->flags5),f))
42404 {
42405 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42406 }
42407
42408 if(!p_igetw(&(m->noreset),f))
42409 {
42410 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42411 }
42412
42413 if(!p_igetw(&(m->nocarry),f))
42414 {
42415 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42416 }
42417
42418 if(!p_getc(&(m->flags6),f))
42419 {
42420 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42421 }
42422
42423 if(!p_getc(&(m->flags7),f))
42424 {
42425 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42426 }
42427
42428 if(!p_getc(&(m->flags8),f))
42429 {
42430 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42431 }
42432
42433 if(!p_getc(&(m->flags9),f))
42434 {
42435 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42436 }
42437
42438 if(!p_getc(&(m->flags10),f))
42439 {
42440 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42441 }
42442
42443 if(!p_getc(&(m->csensitive),f))
42444 {
42445 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42446 }
42447
42448 if(!p_getc(&(m->oceansfx),f))
42449 {
42450 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42451 }
42452
42453 if(!p_getc(&(m->bosssfx),f))
42454 {
42455 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42456 }
42457
42458 if(!p_getc(&(m->secretsfx),f))
42459 {
42460 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42461 }
42462
42463 if(!p_getc(&(m->holdupsfx),f))
42464 {
42465 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42466 }
42467
42468 for(int32_t k=0; k<6; k++)
42469 {
42470 if(!p_getc(&(m->layermap[k]),f))
42471 {
42472 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42473 }
42474 }
42475
42476 for(int32_t k=0; k<6; k++)
42477 {
42478 if(!p_getc(&(m->layerscreen[k]),f))
42479 {
42480 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42481 }
42482 }
42483
42484 for(int32_t k=0; k<6; k++)
42485 {
42486 if(!p_getc(&(m->layeropacity[k]),f))
42487 {
42488 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42489 }
42490 }
42491
42492 if(!p_igetw(&(m->timedwarptics),f))
42493 {
42494 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42495 }
42496
42497 if(!p_getc(&(m->nextmap),f))
42498 {
42499 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42500 }
42501
42502 if(!p_getc(&(m->nextscr),f))
42503 {
42504 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42505 }
42506
42507 for(int32_t k=0; k<128; k++)
42508 {
42509 if(!p_igetw(&(m->secretcombo[k]),f))
42510 {
42511 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42512 }
42513 }
42514
42515 for(int32_t k=0; k<128; k++)
42516 {
42517 if(!p_getc(&(m->secretcset[k]),f))
42518 {
42519 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42520 }
42521 }
42522
42523 for(int32_t k=0; k<128; k++)
42524 {
42525 if(!p_getc(&(m->secretflag[k]),f))
42526 {
42527 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42528 }
42529 }
42530
42531 for(int32_t k=0; k<176; k++)
42532 {
42533 try
42534 {
42535 if(!p_igetw(&(m->data[k]),f))
42536 {
42537 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42538 }
42539 }
42540 catch(std::out_of_range& )
42541 {
42542 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42543 }
42544 }
42545
42546 for(int32_t k=0; k<176; k++)
42547 {
42548 try
42549 {
42550 if(!p_getc(&(m->sflag[k]),f))
42551 {
42552 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42553 }
42554 }
42555 catch(std::out_of_range& )
42556 {
42557 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42558 }
42559 }
42560
42561 for(int32_t k=0; k<176; k++)
42562 {
42563 try
42564 {
42565 if(!p_getc(&(m->cset[k]),f))
42566 {
42567 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42568 }
42569 }
42570 catch(std::out_of_range& )
42571 {
42572 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42573 }
42574 }
42575
42576 if(!p_igetw(&(m->screen_midi),f))
42577 {
42578 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42579 }
42580
42581 if(!p_getc(&(m->lens_layer),f))
42582 {
42583 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42584 }
42585
42586 m->ensureFFC(32);
42587 word tempw;
42588 for(int32_t k=0; k<32; k++)
42589 {
42590 ffcdata& ffc = m->ffcs[k];
42591 if(!p_igetw(&tempw,f))
42592 {
42593 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42594 }
42595 zc_ffc_set(ffc, tempw);
42596
42597 if(!p_getc(&(ffc.cset),f))
42598 {
42599 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42600 }
42601
42602 if(!p_igetw(&(ffc.delay),f))
42603 {
42604 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42605 }
42606
42607 if(!p_igetzf(&(ffc.x),f))
42608 {
42609 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42610 }
42611
42612 if(!p_igetzf(&(ffc.y),f))
42613 {
42614 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42615 }
42616
42617 if(!p_igetzf(&(ffc.vx),f))
42618 {
42619 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42620 }
42621
42622 if(!p_igetzf(&(ffc.vy),f))
42623 {
42624 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42625 }
42626
42627 if(!p_igetzf(&(ffc.ax),f))
42628 {
42629 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42630 }
42631
42632 if(!p_igetzf(&(ffc.ay),f))
42633 {
42634 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42635 }
42636
42637 if(!p_getc(&(ffc.link),f))
42638 {
42639 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42640 }
42641
42642 if(!p_igetl(&(ffc.hit_width),f))
42643 {
42644 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42645 }
42646
42647 if(!p_igetl(&(ffc.hit_height),f))
42648 {
42649 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42650 }
42651
42652 if(!p_getc(&(ffc.txsz),f))
42653 {
42654 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42655 }
42656
42657 if(!p_getc(&(ffc.tysz),f))
42658 {
42659 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42660 }
42661
42662 if(!p_igetl(&(ffc.flags),f))
42663 {
42664 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42665 }
42666
42667 if(!p_igetw(&(ffc.script),f))
42668 {
42669 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42670 }
42671
42672 if(!p_igetl(&(ffc.initd[0]),f))
42673 {
42674 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42675 }
42676
42677 if(!p_igetl(&(ffc.initd[1]),f))
42678 {
42679 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42680 }
42681
42682 if(!p_igetl(&(ffc.initd[2]),f))
42683 {
42684 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42685 }
42686
42687 if(!p_igetl(&(ffc.initd[3]),f))
42688 {
42689 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42690 }
42691
42692 if(!p_igetl(&(ffc.initd[4]),f))
42693 {
42694 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42695 }
42696
42697 if(!p_igetl(&(ffc.initd[5]),f))
42698 {
42699 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42700 }
42701
42702 if(!p_igetl(&(ffc.initd[6]),f))
42703 {
42704 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42705 }
42706
42707 if(!p_igetl(&(ffc.initd[7]),f))
42708 {
42709 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42710 }
42711
42712 }
42713
42714 if(!p_igetw(&(m->script),f))
42715 {
42716 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42717 }
42718 for ( int32_t q = 0; q < 8; q++ )
42719 {
42720 if(!p_igetl(&(m->screeninitd[q]),f))
42721 {
42722 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42723 }
42724
42725 }
42726 if(!p_getc(&(m->preloadscript),f))
42727 {
42728 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42729 }
42730
42731 if ( vers_id >= 2 )
42732 {
42733 if(!p_getc(&(m->hidelayers),f))
42734 {
42735 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42736 }
42737 if(!p_getc(&(m->hidescriptlayers),f))
42738 {
42739 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
42740 }
42741
42742 }
42743
42744
42745 }//end mapscr all for loop
42746
42747 }
42748 }
42749 /*
42750 void FFScript::write_maps(PACKFILE *f, int32_t vers_id)
42751 {
42752 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
42753 {
42754 for(int32_t j=0; j<MAPSCRS; j++)
42755 {
42756 if ( !(FFCore.write_mapscreen(f,i,j,vers_id)) )
42757 {
42758 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODE: %d",i*j);
42759 }
42760 }
42761 }
42762 }
42763
42764 void FFScript::read_maps(PACKFILE *f, int32_t vers_id)
42765 {
42766 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
42767 {
42768 for(int32_t j=0; j<MAPSCRS; j++)
42769 {
42770 if ( !(FFCore.read_mapscreen(f,i,j,vers_id)) )
42771 {
42772 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE: %d",i*j);
42773 }
42774 }
42775 }
42776 }
42777 */
42778
42779
42780 int32_t FFScript::getHeroOTile(int32_t index1, int32_t index2)
42781 {
42782 {
42783 herospritetype lst = (herospritetype)index1;
42784 int32_t dir = index2;
42785 int32_t the_ret = 0;
42786 switch(lst)
42787 {
42788 case LSprwalkspr: the_ret = walkspr[dir][0]; break;
42789 case LSprstabspr: the_ret = stabspr[dir][0]; break;
42790 case LSprslashspr: the_ret = slashspr[dir][0]; break;
42791 case LSprrevslashspr: the_ret = revslashspr[dir][0]; break;
42792 case LSprfloatspr: the_ret = floatspr[dir][0]; break;
42793 case LSprswimspr: the_ret = swimspr[dir][0]; break;
42794 case LSprdivespr: the_ret = divespr[dir][0]; break;
42795 case LSprdrownspr: the_ret = drowningspr[dir][0]; break;
42796 case LSprsidedrownspr: the_ret = sidedrowningspr[dir][0]; break;
42797 case LSprlavadrownspr: the_ret = drowning_lavaspr[dir][0]; break;
42798 case LSprsideswimspr: the_ret = sideswimspr[dir][0]; break;
42799 case LSprsideswimslashspr: the_ret = sideswimslashspr[dir][0]; break;
42800 case LSprsideswimstabspr: the_ret = sideswimstabspr[dir][0]; break;
42801 case LSprsideswimpoundspr: the_ret = sideswimpoundspr[dir][0]; break;
42802 case LSprsideswimchargespr: the_ret = sideswimchargespr[dir][0]; break;
42803 case LSprpoundspr: the_ret = poundspr[dir][0]; break;
42804 case LSprjumpspr: the_ret = jumpspr[dir][0]; break;
42805 case LSprchargespr: the_ret = chargespr[dir][0]; break;
42806 case LSprcastingspr: the_ret = castingspr[0]; break;
42807 case LSprsideswimcastingspr: the_ret = sideswimcastingspr[0]; break;
42808 case LSprholdspr1: the_ret = holdspr[0][0][0]; break;
42809 case LSprholdspr2: the_ret = holdspr[0][1][0]; break;
42810 case LSprholdsprw1: the_ret = holdspr[1][0][0]; break;
42811 case LSprholdsprw2: the_ret = holdspr[1][1][0]; break;
42812 case LSprholdsprSw1: the_ret = sideswimholdspr[0][0]; break;
42813 case LSprholdsprSw2: the_ret = sideswimholdspr[1][0]; break;
42814 default: the_ret = 0;
42815 }
42816
42817 return the_ret*10000;
42818 }
42819 }
42820
42821 defWpnSprite FFScript::getDefWeaponSprite(int32_t wpnid)
42822 {
42823 switch(wpnid)
42824 {
42825 case wNone: return ws_0;
42826 case wSword: return ws_0;
42827 case wBeam: return wsBeam;
42828 case wBrang : return wsBrang;
42829 case wBomb: return wsBomb;
42830 case wSBomb: return wsSBomb;
42831 case wLitBomb: return wsBombblast;
42832 case wLitSBomb: return wsBombblast;
42833 case wArrow: return wsArrow;
42834 case wRefArrow: return wsArrow;
42835 case wFire: return wsFire;
42836 case wRefFire: return wsFire;
42837 case wRefFire2: return wsFire;
42838 case wWhistle: return wsUnused45;
42839 case wBait: return wsBait;
42840 case wWand: return wsWandHandle;
42841 case wMagic: return wsMagic;
42842 case wCatching: return wsUnused45;
42843 case wWind: return wsWind;
42844 case wRefMagic: return wsRefMagic;
42845 case wRefFireball: return wsRefFireball;
42846 case wRefRock: return wsRock;
42847 case wHammer: return wsHammer;
42848 case wHookshot: return wsHookshotHead;
42849 case wHSHandle: return wsHookshotHandle;
42850 case wHSChain: return wsHookshotChainH;
42851 case wSSparkle: return wsSilverSparkle;
42852 case wFSparkle: return wsGoldSparkle;
42853 case wSmack: return wsHammerSmack;
42854 case wPhantom: return wsUnused45;
42855 case wCByrna: return wsByrnaCane;
42856 case wRefBeam: return wsRefBeam;
42857 case wStomp: return wsUnused45;
42858 case lwMax: return wsUnused45;
42859 case wScript1:
42860 case wScript2:
42861 case wScript3:
42862 case wScript4:
42863 case wScript5:
42864 case wScript6:
42865 case wScript7:
42866 case wScript8:
42867 case wScript9:
42868 case wScript10: return ws_0;
42869 case wIce: return wsIce; //new
42870 case wFlame: return wsEFire2; //new
42871 //not implemented; t/b/a
42872 case wSound:
42873 case wThrown:
42874 case wPot:
42875 case wLit:
42876 case wBombos:
42877 case wEther:
42878 case wQuake:
42879 case wSword180:
42880 case wSwordLA: return wsUnused45;
42881
42882 case ewFireball: return wsFireball2;
42883 case ewArrow: return wsEArrow;
42884 case ewBrang: return wsBrang;
42885 case ewSword: return wsEBeam;
42886 case ewRock: return wsRock;
42887 case ewMagic: return wsEMagic;
42888 case ewBomb: return wsEBomb;
42889 case ewSBomb: return wsESbomb;
42890 case ewLitBomb: return wsEBombblast;
42891 case ewLitSBomb: return wsESbombblast;
42892 case ewFireTrail: return wsEFiretrail;
42893 case ewFlame: return wsEFire;
42894 case ewWind: return wsEWind;
42895 case ewFlame2: return wsEFire2;
42896 case ewFlame2Trail: return wsEFiretrail2;
42897 case ewIce: return wsIce;
42898 case ewFireball2: return wsFireball2;
42899 default: return wsUnused45;
42900 }
42901 };
42902
42903 598 void FFScript::do_loadlweapon_by_script_uid(const bool v)
42904 {
42905 598 int32_t uid = SH::get_arg(sarg1, v);
42906
1/2
✓ Branch 0 taken 598 times.
✗ Branch 1 not taken.
598 if (ResolveLWeapon_checkSpriteList(uid))
42907 598 ri->lwpn = uid;
42908 else
42909 {
42910 ri->lwpn = 0;
42911 }
42912 598 }
42913
42914 void FFScript::do_loadeweapon_by_script_uid(const bool v)
42915 {
42916 int32_t uid = SH::get_arg(sarg1, v);
42917 if (ResolveEWeapon_checkSpriteList(uid))
42918 ri->ewpn = uid;
42919 else
42920 {
42921 ri->ewpn = 0;
42922 }
42923 }
42924
42925
42926 12 void FFScript::do_loadnpc_by_script_uid(const bool v)
42927 {
42928 12 int32_t uid = SH::get_arg(sarg1, v);
42929
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (ResolveSprite<enemy>(uid, "enemy"))
42930 12 ri->guyref = uid;
42931 else
42932 {
42933 ri->guyref = 0;
42934 }
42935 12 }
42936
42937 //Combo Scripts
42938
42939 98880 void FFScript::clear_combo_scripts()
42940 {
42941 98880 combo_id_cache.clear();
42942 98880 combo_id_cache.resize(region_num_rpos * 7);
42943 98880 std::fill(combo_id_cache.begin(), combo_id_cache.end(), -1);
42944 98880 clear_script_engine_data_of_type(ScriptType::Combo);
42945 98880 }
42946
42947 8190 void FFScript::clear_combo_script(const rpos_handle_t& rpos_handle)
42948 {
42949 8190 int32_t index = get_combopos_ref(rpos_handle);
42950 8190 combo_id_cache[index] = -1;
42951 8190 combopos_modified = index;
42952 8190 clear_script_engine_data(ScriptType::Combo, index);
42953 8190 }
42954
42955 3712326 int32_t FFScript::combo_script_engine(const bool preload, const bool waitdraw)
42956 {
42957 bool enabled[7];
42958
2/2
✓ Branch 0 taken 25986282 times.
✓ Branch 1 taken 3712326 times.
29698608 for (int32_t q = 0; q < 7; ++q)
42959 {
42960 25986282 enabled[q] = get_qr(qr_COMBOSCRIPTS_LAYER_0 + q);
42961 25986282 }
42962
42963 3712326 auto& combo_cache = combo_caches::script;
42964
42965 ///non-scripted effects
42966 2310016150 for_every_rpos([&](const rpos_handle_t& rpos_handle) {
42967
2/2
✓ Branch 0 taken 851561744 times.
✓ Branch 1 taken 1454742080 times.
2306303824 if (!enabled[rpos_handle.layer])
42968 1454742080 return;
42969
42970 851561744 int32_t combopos_ref = get_combopos_ref(rpos_handle);
42971 851561744 word cid = rpos_handle.data();
42972
2/2
✓ Branch 0 taken 850456278 times.
✓ Branch 1 taken 1105466 times.
851561744 if(combo_id_cache[combopos_ref] != cid)
42973 {
42974 1105466 combopos_modified = combopos_ref;
42975 1105466 combo_id_cache[combopos_ref] = cid;
42976 1105466 clear_script_engine_data(ScriptType::Combo, combopos_ref);
42977 1105466 }
42978
42979 851561744 auto script = combo_cache.minis[cid].script;
42980
2/2
✓ Branch 0 taken 842970014 times.
✓ Branch 1 taken 8591730 times.
851561744 if (script)
42981 {
42982 8591730 auto& data = get_script_engine_data(ScriptType::Combo, combopos_ref);
42983
2/2
✓ Branch 0 taken 7870889 times.
✓ Branch 1 taken 720841 times.
8591730 if (data.doscript)
42984 {
42985
4/4
✓ Branch 0 taken 356612 times.
✓ Branch 1 taken 364229 times.
✓ Branch 2 taken 352329 times.
✓ Branch 3 taken 4283 times.
720841 if (waitdraw && !data.waitdraw) return; //waitdraw not set
42986
42987 368512 ZScriptVersion::RunScript(ScriptType::Combo, script, combopos_ref);
42988
2/2
✓ Branch 0 taken 364229 times.
✓ Branch 1 taken 4283 times.
368512 if (waitdraw) data.waitdraw = true;
42989 368512 }
42990 8239401 }
42991 2306303824 });
42992
42993 3712326 return 1;
42994 }
42995
42996 792477 int32_t FFScript::Distance(double x1, double y1, double x2, double y2)
42997 {
42998 792477 double x = (x1-x2);
42999 792477 double y = (y1-y2);
43000 792477 double sum = (x*x)+(y*y);
43001 //if(((int32_t)sum) < 0)
43002 //{
43003 // Z_scripterrlog("Distance() attempted to calculate square root of %ld!\n", ((int32_t)sum));
43004 // return -10000;;
43005 //}
43006 792477 sum *= 1000000.0;
43007 792477 double total = sqrt(sum)*10;
43008 792477 return int32_t(total);
43009 }
43010
43011 int32_t FFScript::Distance(double x1, double y1, double x2, double y2, int32_t scale)
43012 {
43013 double x3 = x1+(x2-x1)/scale;
43014 double y3 = y1+(y2-y1)/scale;
43015 //double sum = (x*x)+(y*y);
43016 //if(((int32_t)sum) < 0)
43017 //{
43018 // Z_scripterrlog("Distance() attempted to calculate square root of %ld!\n", ((int32_t)sum));
43019 // return -10000;
43020 //}
43021 //sum *= 1000000.0;
43022 //double total = sqrt(sum)*10;
43023 //return int32_t(total*scale);
43024 return (FFCore.Distance(x1, y1, x3, y3)*scale);
43025 }
43026
43027 int32_t FFScript::LongDistance(double x1, double y1, double x2, double y2)
43028 {
43029 double x = (x1-x2);
43030 double y = (y1-y2);
43031 double sum = (x*x)+(y*y);
43032 //if(((int32_t)sum) < 0)
43033 //{
43034 // Z_scripterrlog("Distance() attempted to calculate square root of %ld!\n", ((int32_t)sum));
43035 // return -10000;;
43036 //}
43037 double total = sqrt(sum);
43038 return int32_t(total);
43039 }
43040
43041 int32_t FFScript::LongDistance(double x1, double y1, double x2, double y2, int32_t scale)
43042 {
43043 double x3 = x1+(x2-x1)/scale;
43044 double y3 = y1+(y2-y1)/scale;
43045 //double sum = (x*x)+(y*y);
43046 //if(((int32_t)sum) < 0)
43047 //{
43048 // Z_scripterrlog("Distance() attempted to calculate square root of %ld!\n", ((int32_t)sum));
43049 // return -10000;
43050 //}
43051 //sum *= 1000000.0;
43052 //double total = sqrt(sum)*10;
43053 //return int32_t(total*scale);
43054 return (FFCore.LongDistance(x1, y1, x3, y3)*scale);
43055 }
43056
43057 338749205 bool command_is_wait(int command)
43058 {
43059
2/2
✓ Branch 0 taken 338627159 times.
✓ Branch 1 taken 122046 times.
338749205 switch (command)
43060 {
43061 case WAITFRAME:
43062 case WAITDRAW:
43063 case WAITTO:
43064 case WAITEVENT:
43065 case WAITFRAMESR:
43066 122046 return true;
43067 }
43068 338627159 return false;
43069 338749205 }
43070
43071 227871646 bool command_is_goto(int command)
43072 {
43073 // GOTOR/return ops left out on purpose.
43074
2/2
✓ Branch 0 taken 211110507 times.
✓ Branch 1 taken 16761139 times.
227871646 switch (command)
43075 {
43076 case GOTO:
43077 case GOTOCMP:
43078 case GOTOLESS:
43079 case GOTOMORE:
43080 case GOTOTRUE:
43081 case GOTOFALSE:
43082 16761139 return true;
43083 }
43084 211110507 return false;
43085 227871646 }
43086
43087 116874369 bool command_uses_comparison_result(int command)
43088 {
43089
2/2
✓ Branch 0 taken 112506337 times.
✓ Branch 1 taken 4368032 times.
116874369 switch (command)
43090 {
43091 case GOTOTRUE:
43092 case GOTOFALSE:
43093 case GOTOMORE:
43094 case GOTOLESS:
43095 case GOTOCMP:
43096 case SETCMP:
43097 case SETTRUE:
43098 case SETTRUEI:
43099 case SETFALSE:
43100 case SETFALSEI:
43101 case SETMOREI:
43102 case SETLESSI:
43103 case SETMORE:
43104 case SETLESS:
43105 case STACKWRITEATVV_IF:
43106 4368032 return true;
43107 }
43108 112506337 return false;
43109 116874369 }
43110
43111 194234297 bool command_writes_comparison_result(int command)
43112 {
43113
2/2
✓ Branch 0 taken 186146381 times.
✓ Branch 1 taken 8087916 times.
194234297 switch (command)
43114 {
43115 case SETCMP:
43116 case SETTRUE:
43117 case SETTRUEI:
43118 case SETFALSE:
43119 case SETFALSEI:
43120 case SETMOREI:
43121 case SETLESSI:
43122 case SETMORE:
43123 case SETLESS:
43124 8087916 return true;
43125 }
43126 186146381 return false;
43127 194234297 }
43128
43129 12888727 int command_to_cmp(int command, int arg)
43130 {
43131
12/14
✓ Branch 0 taken 1674098 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3259429 times.
✓ Branch 3 taken 4132 times.
✓ Branch 4 taken 79434 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3125759 times.
✓ Branch 7 taken 1424892 times.
✓ Branch 8 taken 1843162 times.
✓ Branch 9 taken 776217 times.
✓ Branch 10 taken 426837 times.
✓ Branch 11 taken 52188 times.
✓ Branch 12 taken 185290 times.
✓ Branch 13 taken 37289 times.
12888727 switch (command)
43132 {
43133 case SETCMP:
43134 case GOTOCMP:
43135 1674098 return arg;
43136
43137 case GOTOTRUE:
43138 3259429 return CMP_EQ;
43139 case GOTOFALSE:
43140 4132 return CMP_NE;
43141 case GOTOMORE:
43142 79434 return CMP_GE;
43143 case GOTOLESS:
43144 return get_qr(qr_GOTOLESSNOTEQUAL) ? CMP_LE : CMP_LT;
43145
43146 case SETTRUE:
43147 3125759 return CMP_EQ;
43148 case SETFALSE:
43149 1424892 return CMP_NE;
43150 case SETMORE:
43151 1843162 return CMP_GE;
43152 case SETLESS:
43153 776217 return CMP_LE;
43154
43155 case SETTRUEI:
43156 426837 return CMP_SETI|CMP_EQ;
43157 case SETFALSEI:
43158 52188 return CMP_SETI|CMP_NE;
43159 case SETMOREI:
43160 185290 return CMP_SETI|CMP_GE;
43161 case SETLESSI:
43162 37289 return CMP_SETI|CMP_LE;
43163 }
43164
43165 ASSERT(false);
43166 return 0;
43167 12888727 }
43168
43169 1279557 bool command_could_return_not_ok(int command)
43170 {
43171
2/2
✓ Branch 0 taken 1273166 times.
✓ Branch 1 taken 6391 times.
1279557 switch (command)
43172 {
43173 case 0xFFFF:
43174 case EWPNDEL:
43175 case GAMECONTINUE:
43176 case GAMEEND:
43177 case GAMEEXIT:
43178 case GAMERELOAD:
43179 case GAMESAVECONTINUE:
43180 case GAMESAVEQUIT:
43181 case ITEMDEL:
43182 case LWPNDEL:
43183 case NPCKICKBUCKET:
43184 6391 return true;
43185 }
43186 1273166 return false;
43187 1279557 }
43188
43189 166507901 bool command_is_pure(int command)
43190 {
43191
2/2
✓ Branch 0 taken 115335295 times.
✓ Branch 1 taken 51172606 times.
166507901 switch (command)
43192 {
43193 case ABS:
43194 case ADDR:
43195 case ADDV:
43196 case ANDR:
43197 case ANDR32:
43198 case ANDV:
43199 case ANDV32:
43200 case ARCCOSR:
43201 case ARCCOSV:
43202 case ARCSINR:
43203 case ARCSINV:
43204 case BITNOT:
43205 case BITNOT32:
43206 case CASTBOOLF:
43207 case CEILING:
43208 case COMPAREV2:
43209 case COSR:
43210 case COSV:
43211 case DIVV2:
43212 case FACTORIAL:
43213 case FLOOR:
43214 case IPOWERR:
43215 case IPOWERV:
43216 case ISALLOCATEDBITMAP:
43217 case LOAD:
43218 case LOADD:
43219 case LOADI:
43220 case LOG10:
43221 case LOGE:
43222 case LSHIFTR:
43223 case LSHIFTR32:
43224 case LSHIFTV:
43225 case LSHIFTV32:
43226 case MAXR:
43227 case MAXV:
43228 case MAXVARG:
43229 case MINR:
43230 case MINV:
43231 case MINVARG:
43232 case MODR:
43233 case MODV:
43234 case MODV2:
43235 case NANDR:
43236 case NANDV:
43237 case NORR:
43238 case NORV:
43239 case NOT:
43240 case ORR:
43241 case ORR32:
43242 case ORV:
43243 case ORV32:
43244 case PEEK:
43245 case PEEKATV:
43246 case POWERR:
43247 case POWERV:
43248 case ROUND:
43249 case ROUNDAWAY:
43250 case RSHIFTR:
43251 case RSHIFTR32:
43252 case RSHIFTV:
43253 case RSHIFTV32:
43254 case SETCMP:
43255 case SETFALSE:
43256 case SETFALSEI:
43257 case SETLESS:
43258 case SETLESSI:
43259 case SETMORE:
43260 case SETMOREI:
43261 case SETR:
43262 case SETTRUE:
43263 case SETTRUEI:
43264 case SETV:
43265 case SINR:
43266 case SINV:
43267 case SUBR:
43268 case SUBV:
43269 case SUBV2:
43270 case TANR:
43271 case TANV:
43272 case TOBYTE:
43273 case TOINTEGER:
43274 case TOSHORT:
43275 case TOSIGNEDBYTE:
43276 case TOWORD:
43277 case TRUNCATE:
43278 case XNORR:
43279 case XNORV:
43280 case XORR:
43281 case XORR32:
43282 case XORV:
43283 case XORV32:
43284 51172606 return true;
43285 }
43286
43287 115335295 return false;
43288 166507901 }
43289
43290 851582288 int32_t get_combopos_ref(const rpos_handle_t& rpos_handle)
43291 {
43292 851582288 return rpos_handle.layer * region_num_rpos + (int)rpos_handle.rpos;
43293 }
43294
43295 int32_t get_combopos_ref(rpos_t rpos, int32_t layer)
43296 {
43297 return layer * region_num_rpos + (int)rpos;
43298 }
43299
43300 649434 rpos_t combopos_ref_to_rpos(int32_t combopos_ref)
43301 {
43302 649434 return (rpos_t)(combopos_ref % region_num_rpos);
43303 }
43304
43305 387550 int32_t combopos_ref_to_layer(int32_t combopos_ref)
43306 {
43307 387550 return combopos_ref / region_num_rpos;
43308 }
43309